How is std::unique_ptr implemented to ensure only one owner exists? How does it differ from std::shared_ptr in terms of memory overhead?

Last updated 21 June 2026

  • std::unique_ptr enforces single ownership by deleting its copy constructor and copy assignment (= delete). Only moves are allowed, and they null out the source.

  • With the default deleter it is the size of a raw pointer: no control block and no atomic counters, so zero overhead.

  • std::shared_ptr is typically two pointers wide (object + control block) and pays for atomic strong/weak count updates on every copy and destruction.

  • https://www.interviewbit.com/cpp-interview-questions/
  • https://www.geeksforgeeks.org/interview-prep/advanced-topics-design-patterns-interview-questions-c-programming/
All C++ interview questions