Boost Users :
Subject: Re: [Boost-users] How can I use unique_ptr with container and string in boost::interprocess?
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2008-10-21 12:41:39
> I have a complex data structure that wants to put into shared memory.
> In STL way it should be:
> In this way, I always must construct a SharedMemoryString first then put it
> into container:
> SharedMemoryString mStr(charAlloc);
> mStr = "some stirng...";
> In my understanding, this will cost twice memory allocations to store this
> string into shared memory.
> First time is mStr = "some string...", second time is that mStr is put into
> list container, then mStr's memory will be destructed after leaving the
I have no compiler at hand to test the unique_ptr issue, but you can use
move semantics to avoid memory allocations:
//transfer resources from mStr to the newly
should work. Also:
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net