检查 Boost Interprocess managed_shared_memory 是否已经存在?

Check if Boost Interprocess managed_shared_memory already exists?

有没有办法(除了 try-catch)来确定具有特定名称的 boost::interprocess:managed_shared_memory 区域是否已经存在?

我知道如果我在 managed_shared_memory 区域内分配进程间向量,我可以使用 managed_shared_memory::find() 检查它是否存在,但似乎没有办法检查 managed_shared_memory 是否存在=17=] 区域本身存在。

您可以将构造函数与 boost::interprocess::open_or_create 一起使用。

如果您想知道两者中的哪一个发生了,您可以使用 boost::interprocess::open_onlyboost::interprocess::create_only,但您需要在顶部添加 "external" 同步: