C Unique Ptr Vs Shared Ptr
- Get link
- 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.
The obvious difference is that you can have many consumers sharing responsibility for a dynamic object (hence "shared"), and the. Note that std::shared_ptr behaves differently: std::shared_ptr<B> will use the operator delete for the type T and the owned object will be deleted correctly even if the destructor of Unlike std::shared_ptr, std::unique_ptr may manage an object through any custom handle type that satisfies NullablePointer. 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 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
- Other Apps
Comments
Post a Comment