我有一个简单的结构:
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/