3 thoughts on “GotW #103: Solution

  1. There is one case I can think of where one might prefer to avoid using make_shared. If you know that there will be many weak_ptrs pointing to your object whose lifetime is longer than the shared object itself.

    In the case of using make_shared the memory for the entire memory block will only be released after all the weak_ptrs are destroyed while in the case of regular new the memory block of the object will be released when all strong pointers are gone and only the memory block for the reference counts will stay around waiting for the weak_ptrs to die.

  2. I would like to see non-thread safe shared pointer. Why? It is huge overhead inside because of atomic operations. Examples of single-threaded applications: SolidWorks, AutoCad, etc. Why should I pay for thread-safety in non-threaded environment? I’ll be happy with some std::intrusive_ptr…

Comments are closed.