[EMCpp]Item-19 Use std::Shared_ptr for Shared-ownership Resource Management
· ☕ 5 min read
std::shared_ptrs
offer convenience approaching that of garbage collection for the shared lifetime management of arbitrary resources.
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.
constexpr
objects are const
and are initialized with values known during compilation; constexpr
functions can produce copmile-time results when called with arguments whose values are know during compilations.