Re: std::make_shared creating a single block?

Discussion in 'C++' started by SG, Nov 21, 2012.

  1. SG

    SG Guest

    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/>
     
    SG, Nov 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page