Chapter 13. Memory Ownership
Memory mismanagement is one of the most common problems in C++ programs. Many of these problems boil down to incorrect assumptions about which part of the code or which entity owns a particular memory. Then we get memory leaks, accessing unallocated memory, excessive memory use, and other difficult to debug problems. Modern C++ has a set of memory ownership idioms, which, taken together, allow the programmer to clearly express the design intent when it comes to memory ownership. This, in turn, makes it much easier to write code that correctly allocates, accesses and deallocates memory.
The following topics are covered in this chapter:
- What is memory ownership?
- What are the characteristics of a well-designed resource ownership?
- When and how to be agnostic about resource ownership?
- How to express exclusive memory ownership in C++?
- How to express shared memory ownership in C++?
- What is the cost of different memory ownership language constructs?