Hi, Evan Torrie wrote:
[snip]
Specifically, say I'm trying to port an existing heap-based structure into shared memory.
struct foo { int x, y; std::vector< std::string > keys; struct foo* left, right; }
struct foo* root;
What would this translate to in the boost::interprocess world?
Something like:
struct foo
{
typedef boost::interprocess::allocator<char> char_allocator_t;
typedef boost::interprocess::
basic_string
Is it possible to write templatized versions of these data structures that would work either with the existing std::allocator heap-based memory or with boost::interprocess stateful allocators without needing to create two versions of this data structure?
Boost Interprocess containers can work with std allocators (code not
compiled, it will surely contain errors):
//This is provided by boost 1.34
#include
One problem I've encountered is that default constructors for boost::interprocess::vector/string etc are not possible since they need to be constructed with a stateful allocator... so, does this mean that any constructor for object foo requires an allocator to be passed in which is then used in the initializer list to initialize these member containers?
Yes. There is no way to have a default constructor, because the allocator needs the address of the shared memory segment and you can have several managed_shared_memory objects around. Hope this helps, Ion