Are there any downsides with using make_shared<T>()
instead of using shared_ptr<T>(new T)
.
Boost documentation states
There have been repeated requests from users for a factory function that creates an object of a given type and returns a shared_ptr to it. Besides convenience and style, such a function is also exception safe and considerably faster because it can use a single allocation for both the object and its corresponding control block, eliminating a significant portion of shared_ptr's construction overhead. This eliminates one of the major efficiency complaints about shared_ptr.
std::make_shared
. Try to use it whenever possible. – Perronshared_ptr
is copied mainly :) – ShouldAll member functions (including copy constructor and copy assignment) can be called by multiple threads on different instances of shared_ptr without additional synchronisation even if these instances are copies and share ownership of the same object.
Which means that the shared data has some kind of synchronisation. (AFAIK implementations usually use atomic operations to increment the counter which make them less performance eaters) – Should