我想使用以下代码将共享向量插入共享地图:
managed_shared_memory segment(create_only ,"MySharedMemory" ,65536);
typedef allocator<int, managed_shared_memory::segment_manager> vecAllocator;
typedef vector<int, vecAllocator> vec;
typedef std::pair<int, vec* > ValueType;
typedef allocator<ValueType, managed_shared_memory::segment_manager> ShmemAllocator;
typedef multimap<int, vec*, std::less<int>, ShmemAllocator> MyMap;
ShmemAllocator alloc_inst (segment.get_segment_manager());
vecAllocator vectorallocator (segment.get_segment_manager());
MyMap *mymap = segment.construct<MyMap>("MyMap")(std::less<int>(),alloc_inst);
vec *myvec = segment.construct<vec>("myvec")(vectorallocator);
vec *myvec1 = segment.construct<vec>("myvec1")(vectorallocator);
myvec->push_back(10);
myvec->push_back(9);
myvec->push_back(8);
myvec1->push_back(987);
myvec1->push_back(123);
myvec1->push_back(456);
for(int i = 0; i < 6; ++i){
for(int j = 0; j<6; j++)
mymap->insert(std::pair<int, vec*>(i, myvec));
}
for(int i = 0; i < 6; ++i){
for(int j = 0; j<6; j++)
mymap->insert(std::pair<int, vec*>(i, myvec1));
}
代码有效..但我想做的是构造一个没有名字的向量。那就是做这样的事情
vec *myvec = segment.construct<vec>(vectorallocator);
vec *myvec1 = segment.construct<vec>(vectorallocator);
因此,如果我将它放在一个循环中,并且每个循环都以不同的方式命名它们是没有问题的。有没有办法这样做?或者至少有一种自动方法可以在每个循环中以不同的方式命名它们?