Memory is a resource that is normally explicitly managed in C++ programs. This management involves the acquisition and disposal of blocks of raw memory.
One of the more delicate issues in managing dynamically allocated memory is the decision of when to deallocate it. Among the various tools to simplify this aspect of programming are so-called smart pointer templates. In C++, smart pointers are classes that behave somewhat like ordinary pointers (in that they provide the dereferencing operators
*) but in addition encapsulate some memory or resource management policy.
In this chapter we develop smart pointer templates that encapsulate two different ownership models—exclusive and shared:
• Exclusive ownership ...