
Ion GaztaƱaga wrote:
Jan Stetka wrote:
Hi,
Is something like this likely to work?
typedef interprocess::vector<int, ShmemAllocator> MyVector
typedef std::pair<const long, MyVector> ValueType;
typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator;
typedef interprocess::map<long, MyVector, std::less<long>, ShmemAllocator> MyMap;
Yes, it should:
#include <boost/interprocess/containers/vector.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/managed_shared_memory.hpp>
using namespace boost::interprocess;
typedef managed_shared_memory::segment_manager Mngr;
typedef allocator<int, Mngr> ShmemIntAllocator; typedef vector<int, ShmemIntAllocator> MyVector; typedef std::pair<const long, MyVector>ValueType; typedef allocator<ValueType, Mngr> ShmemValueTypeAllocator; typedef map<long, MyVector , std::less<long>, ShmemValueTypeAllocator> MyMap;
int main() { { shared_memory_object::remove("name"); managed_shared_memory shmem(open_or_create, "name", 65536);
MyMap *m = shmem.construct<MyMap>("Map name") (std::less<long>(), shmem.get_segment_manager());
//This is the usual way ValueType v(0, MyVector(shmem.get_segment_manager())); m->insert(v); //This is more efficient(data is moved instead of copied) //Note that "long" is not "const long" std::pair<long, MyVector> mv (1, MyVector(shmem.get_segment_manager())); m->insert(move(mv));
//Even more efficient, in-place construction: //the first argument is for the key (long), //the rest are for the mapped type m->emplace(2, shmem.get_segment_manager()); } shared_memory_object::remove("name"); return 0; } _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Does every instance of a container need its own segment?