-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
C++ programmers tend to use destructors to automate the releasing of resources, and this can truly be said to be an idiomatic programming technique in our language, so much that we have given it a name. Probably not the best of names, but a well-known name nonetheless: RAII, which stands for Resource acquisition is initialization (some have also suggested Responsibility acquisition is initialization, which also works and carries a similar meaning). The general idea is that objects tend to acquire resources at construction time (or later), but (and more importantly!) that releasing resources held by an object is something that usually should be done at the end of that object’s lifetime. Thus, RAII has more to do with destructors than with constructors, but as I said, we tend to be bad with names and acronyms.
Revisiting our file reading and processing example from the Managing resources section, earlier in this chapter, we can build an RAII resource handler...