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 problems that are difficult to debug. Modern C++ has a set of memory ownership idioms that, taken together, allow the programmer to clearly express their 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 well-designed resource ownership?
- When and how should we be agnostic about resource ownership?
- How do we express exclusive memory ownership in C++?
- How do we express...