Tuesday, May 1, 2018

c++ - Recommended usage of std::unique_ptr

What are recommended uses of a std::unique_ptr as to specifically where, when, and how is it is best used?



I discovered:



About unique_ptr performances




I already know:




  1. std::unique_ptr was developed in C++11 as a replacement for std::auto_ptr

  2. That a std::unique_ptr has no reference counting and "owns" object it points to

  3. There is no copy/assign with a std::unique_ptr

  4. When I need a unique pointer, std::unique_ptr is the go to structure



What I would like to know:





  1. Is using a std::unique_ptr ever preferable (other than uniqueness) to something
    else? What do I gain in this situation?

  2. If so, under what circumstances and when?

  3. Given the need for move semantics, would this make a std::unique_ptr less favorable
    overall?

  4. If a std::shared_ptr would suffice for dynamic memory management in nearly every
    situation, why does having at my disposal a std::unique_ptr matter (again, other
    than uniqueness)?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...