I'm trying to put up a simple but portable way to use shared memory. Boost::interprocess seemed like a good place to start, but I ran into some problems/concerns.
- Can I somehow query existence of shm segment, preferably using boost API? I could always try to create it using
create_onlyand catch an exception, but that's bad design, I don't want stack unwinding in the "good" path. - Can I truncate the segment even while other processes are attached? (provided I'll handle the synchronization, ofcourse) I suppose all the other processes would have to re-map, would they also have to re-attach?
- Boost doc says that on windows the portable
shared_memory_objectisn't actually shared memory per se, but rather a memory-mapped file. Did I understand that correctly? This means I'll have to use specialized code on windows, which I was trying to avoid. Makes me question Boost's fitness for my purpose, is there an alternative? Instead of fighting with boost, I might as well write platform-specific code myself - in your opinion, would that be worth the effort?
shared_memory_object, whether or not it is backed by a file? Afterall windows shared memory is not that different with it being backed in the pagefile. Do you need to access native shared memory created by an exiting application? From your portability concerns I assume that is not the case, so why not just useshared_memory_object? - Grizzly