Tags » RAII


In my application domain, the following shared object pattern occurs quite frequently:

Typically, Shared is a small, dynamically changing, in-memory, database and two or more threads need to perform asynchronous… 346 more words


C++: Today I Learned How to Use dtor Order to Detect Temporaries

On Friday I wrote the kind of C++ bug you usually write on Fridays: a stupid one. I was trying to create an object that would live exactly until the end of the block using… 733 more words


Rule -1: No dynamic allocation unless necessary

Recently on StackOverflow, an original poster found memory leaks in C++ code. It is easy to spot that there is a raw new without delete… 124 more words

Comma Operator RAII Abuse

Here’s a neat little trick that one of my co-workers, Clint Levijoki, discovered. In C++ you often use an RAII wrapper that you place on the stack if you want to be sure that code gets run at a later point. 519 more words


Mining "Effective C++" for ideas on Swift

Effective C++ by Scott Meyers is an amazingly good book. For me, it is to programming books like Watchmen is to comics – everything else I read, I feel disappointed that it isn’t as good. 1,328 more words


std::ios_base format flags are a resource that needs RAII

Suppose we wanted to write a class Fraction which would come equipped with an input operator>> that would accept input in the form -2/4 or… 1,272 more words


Smart Pointers

Smart Pointers

In modern C++ programming, the Standard Library includes smart pointers, which are used to help ensure that programs are free of memory and resource leaks and are exception-safe. 530 more words