c++ - boost::interprocess : shared memory and STL types

标签 c++ stl boost boost-interprocess

我有一个简单的结构:

struct MyType
{
    std::string name;
    std::string description;
}

我把它放在共享内存中:

managed_shared_memory sharedMemory(open_or_create, "name", 65535);
MyType* pType = sharedMemory.construct<MyType>("myType")();
// ... setting pType members ...

如果与共享内存通信的两个应用程序是使用不同版本的 Visual Studio(不同版本的 STL 实现)构建的,我应该将 native 类型(例如 char*)而不是 STL 类型放在共享内存中吗?

编辑:

我试过

typedef boost::interprocess::basic_string<char> shared_string;

而且有效!

最佳答案

你应该使用

typedef boost::interprocess::basic_string<char> shared_string;
struct MyType
{
    shared_string name;
    shared_string description;
}

关于c++ - boost::interprocess : shared memory and STL types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1272073/

相关文章:

c++ - boost::shared_ptr <> "explicit shared_ptr( Y * p ): px( p ), pn()//Y must be complete"

c++ - OpenMP:通过线程 ID 访问共享变量时是否需要临界区

c++ - Kd-Tree 有缺陷的 K 最近邻

c++ - 当我想要特定参数时, std::map 中的成员方法如何

c++ - 迭代器跳过循环

c++ - C++11 中的 hash_value 函数

c++ - 如何使用 "while loop "打印正确的输出?

c++ - C++ 中的 While 循环结束,但不会继续执行剩余的语句

c++ - 如何从 vector 图中迭代 vector ?

c++ - 带有 unordered_map 的模板代码膨胀