I am trying to have two processes access the same shared memory. I have process1 creating a deque with my_custom_class*. my_custom_class contains some integers.
typedef boost::interprocess::allocator<my_custom_frame*, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
typedef boost::interprocess::deque<my_custom_frame*, ShmemAllocator> VideoDeque;
boost::interprocess::managed_shared_memory segment(boost::interprocess::create_only, "MySharedMemory", 100000000);
video_deque = segment.construct<VideoDeque>("VideoDeque")(alloc_inst);
After creating the deque in the shared memory using the custom allocator I create a my_custom_frame using the allocate method on the shared memory. I first allocate memory for the size of my_custom_frame and then using placement new() I create a my_custom_frame object there.
temp1 = segment.allocate(sizeof(my_custom_frame));
frame1 = (my_custom_frame*) new (temp1) my_custom_frame();
I then set the integers in my_custom_frame by calling a copy_dframe_to_cf method on frame1. I then push frame1 onto video_deque. At this point if I set a break point in my code frame1 has all the integer variables set up properly.
frame1->copy_dframe_to_cf(video_frames[0].get());
video_deque->push_back(frame1);
In process2 I open the shared memory and find my deque.
boost::interprocess::managed_shared_memory segment(boost::interprocess::open_only, "MySharedMemory");
//Find the vector using the c-string name
VideoDeque* my_video_deque = segment.find<VideoDeque>("VideoDeque").first;
I then get the my_custom_frame from my_video_deque.
typedef std::deque<my_custom_frame*> MyFrameQueue;
MyFrameQueue my_video_frames;
my_video_frames.push_back(my_video_deque->front());
my_custom_frame *pFrame;
pFrame = my_video_frames[0];
At this point when I look at the values in pFrame they are all set to 0. The memory address pFrame points to is the same I had put on the deque in process1 so I would like to think I am accessing the same correct memory location but for some reason the values are being reset. Any help would be appreciated.