【问题标题】:boost interprocess : shared memory and stl typesboost interprocess : 共享内存和 stl 类型
【发布时间】:2009-08-13 13:47:02
【问题描述】:

我有一个简单的结构:

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 实现)构建的,我应该将本机类型(例如 char*)而不是 stl 类型放在共享内存中吗?

编辑

我试过了

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

它有效!

【问题讨论】:

    标签: c++ stl boost boost-interprocess


    【解决方案1】:

    你应该使用

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

    【讨论】:

      【解决方案2】:

      Boost.Interprocess 通常提供 STL 类型的替代品,用于共享内存。 std::string,尤其是当只是一个结构的成员时,将无法从另一个进程访问。其他人也有such a problem

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-19
      • 2012-11-05
      • 2015-02-14
      • 2018-10-21
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      相关资源
      最近更新 更多