jeudi 4 juin 2015

Boost::interprocess and scoped_allocator_adaptor

I am attempting to create a vector<string> in shared memory with the string residing in memory as well. Having read a little about scoped_allocator_adaptor, I thought that the following code should do the trick:

typedef std::scoped_allocator_adaptor<boost::interprocess::allocator<void,
        boost::interprocess::managed_shared_memory::segment_manager>>  SharedMemoryAllocator;
typedef std::vector<std::string, SharedMemoryAllocator> SharedMemoryVector;

...

const SharedMemoryAllocator allocator(boostSharedMemory->get_segment_manager());

auto mailbox = boostSharedMemory->construct<SharedMemoryVector>("ShmVector")(allocator);
mailbox->size();

However, on the line with mailbox->size() gcc complains about forming reference to void. I thought part of th e purpose of std::shared_allocator_adaptor is, that I do not have to write complex allocators list.

In other solutions by sehe (i.e. this one), I saw the use of rebind.

question

Is it possible to use containers of conatiners in shared memory by simply passing std::scoped_allocator_adaptor<magic_type, boost::interprocess::managed_shared_memory::segment_manager> to the constructor of the root container? Or am I forced to use rebind, and list according allocators for each type of each nested container? (How would that look exactly?)

Aucun commentaire:

Enregistrer un commentaire