boost vector including non standard objects
Hello!
I would like to create a vector in shared memory which includes objects of
a class Listener*. Listener* was created by my
own and is therefore no standard.
When I try the following, using the boost interprocess library:
typedef boost::interprocess::allocator
El 04/01/2012 16:49, Sabine B escribió:
Hello!
I would like to create a vector in shared memory which includes objects of a class Listener*. Listener* was created by my own and is therefore no standard.
When I try the following, using the boost interprocess library: typedef boost::interprocess::allocator
ShmemAllocator; typedef boost::interprocess::vector MyVector; MyVector *ListenerVector; managed_shared_memory segment(create_only, "MySharedMemory", 65536); const ShmemAllocator alloc_inst(segment.get_segment_manager()); ListenerVector = segment.construct<MyVector>("ListenerVector")(alloc_inst);
ListenerVector->push_back((Listener*)listener);
You can't store raw pointers in shared memory but offset_ptr-s, it's explained in the docs: http://www.boost.org/doc/libs/1_41_0/doc/html/interprocess/sharedmemorybetwe... And you need to allocate listeners also in shared memory using construct (with anonymous name, see docs for details). Best, Ion
participants (2)
-
Ion Gaztañaga
-
Sabine B