Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: std::make_shared creating a single block? (http://www.velocityreviews.com/forums/t954740-re-std-make_shared-creating-a-single-block.html)

SG 11-21-2012 11:24 PM

Re: std::make_shared creating a single block?
 
Am 21.11.2012 23:59, schrieb Andy Champ:
> I came across this reference:
>
> <http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared>
>
> "This function allocates memory for the T object and for the
> shared_ptr's control block with a single memory allocation. In contrast,
> the declaration std::shared_ptr<T> p(new T(Args...)) performs two memory
> allocations, which may incur unnecessary overhead."


As Luca said, it's encounraged, not required.

> The Microsoft compilers allocate two blocks for this, one for the
> control block and one for the object.


Are you really sure? If I remember correctly, Stephan T. Lavavej -- one
of Microsoft's C++ standard library devlopers -- explained how this
one-allocation trick works in one of his pubpicly available lecture
videos [1]. So, I'm surprized to read that you think Microsoft
implements make_shared to use two memory allocations.

Cheers!
SG

[1]
<http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Stephan-T-Lavavej-Standard-Template-Library-STL-3-of-n/>


All times are GMT. The time now is 07:25 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57