O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

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

Item 40. RAII

The C++ community has a long and proud tradition of inscrutable abbreviations and odd names for techniques. RAII manages to attain both oddness and inscrutability. RAII stands for “resource acquisition is initialization.” (No, not “initialization is resource acquisition,” as some would have it. If you’re going to be odd, you’ve got to go all the way or the whole thing falls flat.)

RAII is a simple technique that harnesses C++’s notion of object lifetime to control program resources like memory, file handles, network connections, audit trails, or whatever. The basic technique is simple. If you want to keep track of an important resource, create an object and associate the resource’s lifetime with the object’s lifetime. In that ...

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