-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
In most cases, unique_ptr<T> will be your smart pointer of choice. It’s small, fast, and does what most code requires. There are some specialized but important use cases where unique_ptr<T> is not what you need, and these have in common the following:
Note that if the execution is not concurrent, you will, in general, know who the last owner of the resource is – it’s the last object to observe the resource that will be destroyed in the program. This is an important point – you can have concurrent code that shares resources and still uses unique_ptr to manage the resource. Non-owning users of the resource, such as raw pointers, can access it without taking ownership (more on that later in this chapter), and this approach is sufficient...