My understanding is that a std::unique_ptr
contains the raw pointer as its only member variable, and stores the deleter, if any custom one is given, as part of the type; whereas the std::shared_ptr
stores in member variables the raw as well as the pointer to a dynamically allocated block which contains the custom deleter, and strong and weak counters.
Scott Meyers, in Effective Modern C++, stresses a lot on this difference in the size that the two smart pointers require (and on the difference in performance in general), however I'd be tempted to say that as soon as a std::unique_ptr
is provided with a function pointer as custom deleter it becomes as big as std::shared_ptr
, whose size does not increase with the custom deleter.
From there, I would deduce that using a function pointer as a custom deleter for std::unique_ptr
basically annihilates the advantage this smart pointer has on the other one.
Is this the case?
Aucun commentaire:
Enregistrer un commentaire