[EMCpp]Item-20 Use Weak_ptr for Shared_ptr Like Pointers That Can Dangle
· β 3 min read
Potential use cases for std::weak_ptr
include caching, observer lists, and the prevention of std::shared_ptr
cycles.
Potential use cases for std::weak_ptr
include caching, observer lists, and the prevention of std::shared_ptr
cycles.
std::shared_ptrs
offer convenience approaching that of garbage collection for the shared lifetime management of arbitrary resources.
std::unique_ptr
is a small, fast, move-only smart pointer for managing resources with exclusive-ownership semantics.
The special member functions are those ccompilers may generate on their own: default constructor, destructor, copy operations, and move operations.
Make const
member functions thread safe unless we’re certain they’ll never be used in a concurrent context.