Search code examples
c++boostboost-interprocess

Check if Boost Interprocess managed_shared_memory already exists?


Is there a way (other than a try-catch) to determine whether a boost::interprocess:managed_shared_memory region with a particular name already exists?

I know if I allocate an Interprocess vector within the managed_shared_memory region I can check it's existence using managed_shared_memory::find(), but there doesn't appear to be a way to check whether the managed_shared_memory region itself exists.


Solution

  • You can use the constructor with boost::interprocess::open_or_create.

    If you want to know which of the two happened, you can use boost::interprocess::open_only or boost::interprocess::create_only but you'll have add "external" synchronization on top: c++ Synchronize shared memory when reading