C Unique Ptr Vs Shared Ptr
- Get link
- X
- Other Apps
C Unique Ptr Vs Shared Ptr. A shared_ptr actually sets up a structure in memory which allows for reference counting, weak pointers, etc. If you don't specify the deleter's function signature as the second template parameter, the default_deleter is used.
Unique shared_ptr objects are responsible to delete their managed object if they release.
Protestant divide All std::unique_ptr and std::shared_ptr do is manage the lifetime of dynamic memory objects bound to.
I want to use unique_ptr because i think the states are going to be owned only by Gameclass, so why waste memory using a shared_ptr?. A unique_ptr explicitly prevents copying of its contained pointer (as would happen with normal assignment) A unique_ptr cannot be copied because its copy constructor and assignment operators are A shared_ptr is a container for a raw pointer. unique_ptr is also what auto_ptr wanted to be in the old C++ but couldn't because of that language's limitations. shared_ptr on the other hand is a very different animal.
- Get link
- X
- Other Apps





Comments
Post a Comment