raii Questions
2
Solved
Handles have proper semantics other than pointers. So for me an example like this (extracted from the Rule of Zero):
class module {
public:
explicit module(std::wstring const& name)
: handle ...
Sphacelus asked 14/2, 2013 at 15:22
2
Here's an article that talks about an idiom named Rule of Zero.
Here's an excerpt:
class module {
public:
explicit module(std::wstring const& name)
: handle { ::LoadLibrary(name.c_str()...
Kesler asked 14/2, 2013 at 0:39
5
Solved
I have a class that can throw an exception in its constructor. How can I declare an instance of that class in a try/catch block, while still making it available in the right scope?
try { MyClass l...
Meanwhile asked 5/2, 2013 at 14:52
2
Solved
I've written a RAII wrapper for C function pairs which initialize and release resources and it serves me well for most cases.
#include <GL/glfw.h>
#include <string>
#include <functi...
Ruth asked 19/1, 2013 at 21:16
6
Solved
2
Solved
What is the lifetime of a C++ class member. For example, at which time will the std::fstream of a Foo object be released? When entering the destructor or when leaving the destructor? Is this define...
4
Solved
Let's say I have two local smart pointers, foo and bar.
shared_ptr<Foo> foo = ...
shared_ptr<Bar> bar = ...
These smart pointers are wrappers around resources that for some reason mu...
2
Solved
My code contains snippets like these:
std::va_list ap;
va_start(ap, msgfmt);
snprintf_buf buf;
const tchar * msg = buf.print_va_list(msgfmt, ap);
va_end(ap);
These are short and va_start() ...
Broadcaster asked 27/8, 2012 at 12:14
4
Solved
I have an InfoPath form which I need to conditionally disable it's OnChange events. Since it's not possible to bind the event handlers after the form has loaded, I'm forced to rely on a global coun...
6
Solved
I'm familiar with the advantages of RAII, but I recently tripped over a problem in code like this:
class Foo
{
public:
Foo()
{
DoSomething();
...
}
~Foo()
{
UndoSomething();
}
}
Al...
1
Solved
In C++, when using the Resource Acquisition is Initialization (RAII) pattern, are there any common conventions for naming the classes?
In my case, I have classes which do the following kinds...
Songful asked 2/7, 2012 at 18:18
2
Solved
I know what RAII does. It is all about preventing memory leaks etc. when/if a code throws an exception.
Now, I wish to understand the meaning of that smart term.
http://en.wikipedia.org/wiki/Acqui...
Jasen asked 13/6, 2012 at 12:45
2
Solved
As a follow up to this post I wonder how its implementation of make_unique plays with allocating function-temporary buffer arrays such as in the following code.
f()
{
auto buf = new int[n]; // te...
Hypercatalectic asked 14/4, 2012 at 0:7
1
Solved
The sense I get about this idiom is that it is useful because it ensures that resources are released after the object that uses them goes out of scope.
In other words, it's more about de-acq...
Moulden asked 10/4, 2012 at 19:31
1
Solved
Previously, I'd just dealt with these types of __out function parameters using malloc, but I'm trying to change my ways.
As a specific example, in a class to manage Raw Input, GetRawInputDeviceInf...
3
Solved
I am learning about the RAII idiom in C++, and how to use smart pointers.
In my reading, I have come across two things that, to me, seem to contradict each other.
Quoted from http://www.hackcraft...
Bedrail asked 3/2, 2012 at 0:57
4
Solved
I've recently posted a general question about RAII at SO.
However, I still have some implementation issues with my HANDLE example.
A HANDLE is typedeffed to void * in windows.h. Therefore, the cor...
4
Solved
I have a class that represents a data stream, it basically
reads or writes into a file, but first the data are being encrypted/decrypted and there is also an underlying codec object that handles th...
8
Solved
Consider this simple class that demonstrates RAII in C++ (From the top of my head):
class X {
public:
X() {
fp = fopen("whatever", "r");
if (fp == NULL)
throw some_exception();
}
~X() {
i...
1
Solved
I cannot use boost or the latest std::thread library. The way to go is to create a custom implementation of a scoped mutex.
In a few words when a class instance is create a mutex locks. Upon clas...
4
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 t...
Riddle asked 23/3, 2010 at 18:27
4
Solved
So as I understand it to implement RAII properly, if I where to call CreateFont, I'd wrap that in a class with CreateFont in the constructor and DeleteObject in the destructor, so it cleans it up w...
3
Solved
What is the advantage in de-allocating memory in reverse order to variables?
Courier asked 30/8, 2011 at 9:48
4
Solved
What is a good way in C++ to detect in a destructor that it is being run during unwind of the stack due to an exception being thrown as opposed to a normal exit of scope triggering the destructor? ...
Lovins asked 22/8, 2011 at 1:16
3
Under what circumstances is garbage collection more efficient than manual memory management? (Here manual could mean using malloc and free as in C, or the cleaner RAII and smart pointer techn...
Luciferase asked 8/8, 2011 at 1:14
© 2022 - 2024 — McMap. All rights reserved.