Tuesday, 1 May 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...