Chapter 5. A Comprehensive Look at RAII
Resource management is probably the second most frequent thing a program does, after computing. Note that just because it's frequent, does not mean it's visible: some languages hide much, or all, of the resource management from the user. Just because it is hidden, does not mean it's not there. Every program needs to use some memory, and memory is a resource. A program would be of no use if it never interacted with the outside world in some way, at least to print the result, and input and output channels (files, sockets) are resources. C++, with its zero-overhead abstraction philosophy, does not hide the resources or their management at the core language level. But don't confuse hiding resources with managing them.
The following topics will be covered in this chapter:
- What is considered a "resource" in a C++ program?
- What are the key concerns for managing resources in C++?
- What is the standard approach to managing resources in C++ (the RAII)?
- How does RAII...