- Just a holding wrapper
- Holds an object pointer
- Constructor copies a pointer
- Call proper delete in destructor
- No copying
-
Moving means:
- Copying original pointer to a new object
-
Setting source pointer to
nullptr
- All methods are inline
- Holds an object pointer
-
Holds 2 reference counters:
- shared pointers count
- weak pointers count
-
Destructor:
-
decrements
shared-refs
-
deletes user data when
shared-refs == 0
-
deletes reference counters when
shared-refs == 0
andweak-refs == 0
-
decrements
- Extra space for a deleter
- All methods are inline
-
Copying means:
- Copying pointers to the target
-
Incrementing
shared-refs
-
Moving means:
- Copying pointers to the target
-
Setting source pointers to
nullptr
- Holds an object pointer
-
Holds 2 reference counters:
- shared pointers count
- weak pointers count
-
Destructor:
-
decrements
weak-refs
-
deletes reference counters when
shared-refs == 0
andweak-refs == 0
-
decrements
-
Copying means:
- Copying pointers to the target
-
Incrementing
weak-refs
-
Moving means:
- Copying pointers to the target
-
Setting source pointers to
nullptr
- Having a shared pointer and a weak pointer
- After removing the shared pointer
-
std::shared_ptr<Data> p{new Data};
-
auto p = std::make_shared<Data>();
- Less memory (most likely)
- Only one allocation
- Cache-friendly