O'Reilly logo

Extended STL, Volume 1: Collections and Iterators by Matthew Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. RAII

 

I like to tidy up, because it gives me more room to play.

 
 --Ben Wilson
 

Will you help me to be less naughty, Daddy?

 
 --Harry Wilson

It is reasonable to assume that all C++ practitioners are aware of Resource Acquisition Is Initialization (RAII), even if they do not use that term. Essentially, it is about the business of getting hold of a resource—object, memory, file handle, and so on—in the constructor of an object and releasing it in the destructor. Classes that do this employ RAII and are often referred to as wrapper classes.

In Chapter 3 of Imperfect C++, I defined a taxonomy of RAII that I have found very useful in my work. This involves the permutations between two characteristics: mutability and resource source.

Mutability ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required