aerys / minko

3D framework for web, desktop and mobile devices.
http://minko.io
Other
905 stars 210 forks source link

std::shared_ptr<T>(new T(...)) instead of std::make_shared<T>(...) #205

Closed tforgione closed 9 years ago

tforgione commented 9 years ago

Hi everyone,

I was browsing the source code of this repository, and I was wondering if there was a specific reason for using

auto ptr = std::shared_ptr<T>(new T(...));

instead of

auto ptr = std::make_shared<T>(...);

CppReference says that the second one is faster since it makes only one memory allocation (for the ref counter) but the first version makes one allocation during the new creating the T and another one in the constructor of std::shared_ptr to allocate the ref count.

Thanks in advance.

JMLX42 commented 9 years ago

make_shared require ctors to be public.

tforgione commented 9 years ago

Fair enough, thanks for answering so fast, and sorry for the inconveniance

JMLX42 commented 9 years ago

Note that for the dev branch, the use of shared_ptr has been limited a lot.

There are ways to allow the use of make_shared with private ctors. We might use them in the near future.