I was wondering if there are any differences between the boost::shared_ptr
and the std::shared_ptr
found in the standard <memory>
file.
shared_ptr is now part of the C++11 Standard, as std::shared_ptr . Starting with Boost release 1.53, shared_ptr can be used to hold a pointer to a dynamically allocated array. This is accomplished by using an array type ( T[] or T[N] ) as the template parameter.
this function is deprecated as of C++17 because use_count is only an approximation in multi-threaded environment.
If your C++ implementation supports C++11 (or at least the C++11 shared_ptr ), then std::shared_ptr will be defined in <memory> . If your C++ implementation supports the C++ TR1 library extensions, then std::tr1::shared_ptr will likely be in <memory> (Microsoft Visual C++) or <tr1/memory> (g++'s libstdc++).
The shared_ptr type is a smart pointer in the C++ standard library that is designed for scenarios in which more than one owner might have to manage the lifetime of the object in memory.
std::shared_ptr
is the C++0x form of tr1::shared_ptr
, and boost's boost::shared_ptr
should behave the same.
However, std::shared_ptr
, in an implementation that conforms to C++0x standard, should/might have more convenience behavior on the shared_ptr
class, as described in the following links:
Differences between different flavours of shared_ptr
http://en.wikipedia.org/wiki/C%2B%2B0x#General-purpose_smart_pointers
The
shared_ptr
is a reference-counted pointer that acts as much as possible like a regular C++ data pointer. The TR1 implementation lacked certain pointer features such as aliasing and pointer arithmetic, but the C++0x version will add these.
Though from a quick cursory glance, I do not see operator+
and similar arithmetic operations on the shared_ptr
type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With