I am using boost::interprocess::managed_shared_memory
to create memory to be shared across processes.
Following are the steps taken:
step
a) Create memory.
step
a) Open memory.
b) Write to memory
step
a) Open memory.
b) Read from memory.
c) Open memory.
d) Read from memory.
e) Open memory.
f) Read from memory.
g) ...... and so on and so forth!
Now, the question is, in step number 3, I am opening the memory again-and-again before reading it! I think this is redundant behavior.
How can I read multiple number of times by opening it only once?
Actually the open command is quite expensive in terms of performance, and this is proving to be a bottleneck in my application.
Many of the samples have the managed_shared_memory in the main function for brevity.
You should, however, make it a member of a relevant class (with the responsibility to manage the lifetime of your shared memory mapping).
You could of course, keep it as a local variable in main, but then you'd be forced to keep passing it around in any function calls. (I do NOT recommend making it a global variable. Or a singleton for that matter).