Hi all,
Background: When reading Dr. Stroustrup's papers and FAQs, I notice some strong "opinions" and great advices from legendary CS scientist and programmer. One of them is about shared_ptr in C++0x. He starts explaining about shared_ptr and how it represents shared ownership of the pointed object. At the last line, he says and I quo...
We have 3 different libraries, each developed by a different developer, and each was (presumably) well designed. But since some of the libraries are using RAII and some don't, and some of the libraries are loaded dynamically, and the others aren't - it doesn't work.
Each of the developers is saying that what he is doing is right, and ma...
http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization
Is this design pattern possible in Java? If so, how? If not, why not?
Thanks!
...
RAII = Resource Acuquisation is Initialitazation
Ref Counting = "poor man's GC"
Together, they are quite powerful (like a ref-counted 3D object holding a VBO, which it throws frees when it's destructor is called).
Now, question is -- does RAII exist in any langauge besides C++? In particular, a language that does not allow pointer arit...
In the C++ code below, am I guaranteed that the ~obj() destructor will be called after the // More code executes? Or is the compiler allowed to destruct the obj object earlier if it detects that it's not used?
{
SomeObject obj;
... // More code
}
I'd like to use this technique to save me having to remember to reset a flag at the e...
Is there anyway to implement Resource Acquisation is Initialization in Scheme?
I know that RAII does not work well in GC-ed languages (since we have no idea whe the object is destroyed). However, Scheme has nice things like continuations, dynamic-wind, and closures -- is there a way to use some combination of this to implement RAII?
If...
Something I often used back in C++ was letting a class A handle a state entry and exit condition for another class B, via the A constructor and destructor, to make sure that if something in that scope threw an exception, then B would have a known state when the scope was exited. This isn't pure RAII as far as the acronym goes, but it's a...
Is there any template available in boost for RAII. There are classes like scoped_ptr, shared_ptr which basically work on pointer. Can those classes be used for any other resources other than pointers. Is there any template which works with a general resources.
Take for example some resource which is acquired in the beginning of a scope ...
I see a lot of RAII example classes wrapping around file handles.
I have tried to adapt these examples without luck to a character pointer.
A library that I am using has functions that take the address of a character pointer (declared like get_me_a_string(char **x)).
These functions allocate memory for that character pointer and leave ...
I previously asked this question under another name but deleted it because I didn't explain it very well.
Let's say I have a class which manages a file. Let's say that this class treats the file as having a specific file format, and contains methods to perform operations on this file:
class Foo {
std::wstring fileName_;
public:
...
What is meant by Resource Acquisition is Initialization (RAiI)?
www.technical-interview.com
...
I have a case where I wish to store a list of resources in a std::vector. As I see it, my options are as follows:
Give my resource a default constructor
Store them as heap objects (and wrap them in a shared pointer)
Option 1 makes it possible to construct invalid resources and option 2 forces me to use the heap.
Am I missing any opt...
I'm wondering, for no other purpose than pure curiosity (because no one SHOULD EVER write code like this!) about how the behavior of RAII meshes with the use of Goto (lovely idea isn't it).
class Two
{
public:
~Two()
{
printf("2,");
}
};
class Ghost
{
public:
~Ghost()
{
printf(" BOO! ");
}
};
vo...
Macros are fine.
Templates are fine.
Pretty much whatever it works is fine.
The example is OpenGL; but the technique is C++ specific and relies on no knowledge of OpenGL.
Precise problem:
I want an expression E; where I do not have to specify a unique name; such that a constructor is called where E is defined, and a destructor is call...
Hello everyone :)
I'm very new to anything involving Component Object Model, and I'm wondering if this method of managing calls to CoInitalize/CoUninitalize makes sense:
COM.hpp:
#pragma once
namespace WindowsAPI { namespace ComponentObjectModel {
class COM
{
COM();
~COM();
public:
static void Setup();
};
}}
COM.cpp:
...
I'm a C++ amateur. I'm writing some Win32 API code and there are handles and weirdly compositely allocated objects aplenty. So I was wondering - is there some wrapper class that would make resource management easier?
For example, when I want to load some data I open a file with CreateFile() and get a HANDLE. When I'm done with it, I sho...
in the example below
class X
{
int *r;
public:
X() {
cout << "X is created";
r = new int[10];
};
~X() {
cout<< "X is destroyed";
delete [] r;
};
};
class Y
{
public:
Y() {
X x;
throw 44;
};
~Y() {
cout << "Y is destroyed";
};
};
I got this ...
Say I have a resource (e.g. a filehandle or network socket) which has to be freed:
open my $fh, "<", "filename" or die "Couldn't open filename: $!";
process($fh);
close $fh or die "Couldn't close filename: $!";
Suppose that process might die. Then the code block exits early, and $fh doesn't get closed.
I could explicitly check for er...
We have a large body of native C++ code, compliled into DLLs.
Then we have a couple of dlls containing C++/CLI proxy code to wrap the C++ interfaces.
On top of that we have C# code calling into the C++/CLI wrappers.
Standard stuff, so far.
But we have a lot of cases where native C++ exceptions are allowed to propagate to the .Net wor...
I have some code to update a database table that looks like
try
{
db.execute("BEGIN");
// Lots of DELETE and INSERT
db.execute("COMMIT");
}
catch (DBException&)
{
db.execute("ROLLBACK");
}
I'd like to wrap the transaction logic in an RAII class so I could just write
{
DBTransaction trans(db);
// Lots of DELETE ...