shared_memory_object & managed_shared_memory
This is what I am trying to do - I have to 2 processes in the same box. - I need to send a buffer of data from one process to another. - The other process reads the data & may want to send something back. - At any time there is only one such buffer in process - i.e. no queue of data to send. - the process will send a new buffer only when it gets acknowledgement back from the other process that it's finished reading it. I am a little unclear as to what I should use here - shared_memory_object or managed_shared_memory - it's not very clear what's the difference between the two. I tried out a sample from the condition_variable example here & it seems to work. http://www.boost.org/doc/libs/1_36_0/doc/html/interprocess/synchronization_m... However, in the example the size of the shared memory is based on the size of the trace_queue object. In my case, the size needs to be configurable. so I am thinking of something like this - no data array inside the struct. struct data { data(void * p) : message_in(false), actualdata(p) {} //Mutex to protect access to data boost::interprocess::interprocess_mutex mutex; boost::interprocess::interprocess_condition cond_empty; boost::interprocess::interprocess_condition cond_full; void * actualdata; bool message_in; }; then shared_memory_object shm (create_only ,"shared_memory" ,read_write ); shm.truncate (sizeof(data) + myconfiguredsize); actual data is beyond the struct which holds the condition variable i.e. when i write data, i will do mapped_region region (shm ,read_write ); void * addr = region.get_address(); data * d = new (addr) data(addr); then //Use the condition_variables to protect the write & then memcpy memcpy(d->actualdata, thedataiwanttocopy, sizeofthedataiwanttocopy); Am I doing this the right way or is there a better way to go about this?
participants (1)
-
Just C