Newbie question conerning interprocess stuff
Hi, I'm a complete newbie with boost and have a question concerning the interprocess stuff. I took the piece of code to share a vector in shared memory between two processes from the quick-start guide as a start point and it compiled and ran immediately with success for me. Then I tried to replace the vector by a map: #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/containers/map.hpp> #include <boost/interprocess/allocators/allocator.hpp> using namespace std; int main () { boost::interprocess::shared_memory_object::remove("MySharedMemory"); boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, "MySharedMemory" ,65536); //segment size in bytes typedef pair<const int, int> MyPair; typedef boost::interprocess::allocator<MyPair, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator; typedef boost::interprocess::map<int, int, less<int>, ShmemAllocator> MyMap; const ShmemAllocator alloc_inst (segment.get_segment_manager()); MyMap *mymap = segment.construct<MyMap>("MyMap")(alloc_inst); // mymap->insert(make_pair(1,10)); // mymap->insert(make_pair(2,20)); // mymap->insert(make_pair(3,30)); // mymap->insert(make_pair(4,40)); // mymap->insert(make_pair(5,50)); return 0; } and I wasn't able to compile it any more. (I've put the error message and the sources on the web, find it here: http://www.hottis.de/boost/) I think it is the segment.construct line, although I don't find a direct hint in the error message from the compiler, but if I comment out this line, the compiler is happy. Has any one any hint for me? Thank you very much, Wolfgang
Wolfgang Hottgenroth wrote:
Hi,
I'm a complete newbie with boost and have a question concerning the interprocess stuff.
I took the piece of code to share a vector in shared memory between two processes from the quick-start guide as a start point and it compiled and ran immediately with success for me.
Then I tried to replace the vector by a map:
[snip]
I think it is the segment.construct line, although I don't find a direct hint in the error message from the compiler, but if I comment out this line, the compiler is happy.
Has any one any hint for me?
Map's constructor is: map(const Compare &comp, const allocator_type &a=allocator_type()) so you have to pass the comparison functor apart from the allocator. Try this: MyMap *mymap = segment.construct<MyMap>("MyMap")(std::less<int>(), alloc_inst);
Thank you very much, Wolfgang
Regards, Ion
participants (2)
-
Ion Gaztañaga
-
Wolfgang Hottgenroth