升压进程间:共享内存和STL类型
问题描述:
我有一个简单的结构:升压进程间:共享内存和STL类型
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;
和它的作品!
答
Boost.Interprocess通常提供STL类型的替代品,以便在共享内存中使用。 std :: string,特别是当只有一个结构体的成员时,将不能从另一个进程访问。其他人也有such a problem。
答
您应该使用
typedef boost::interprocess::basic_string<char> shared_string;
struct MyType
{
shared_string name;
shared_string description;
}
呀,请参阅本节文档:http://www.boost.org/doc/libs/1_39_0/doc/html/interprocess/allocators_containers.html#interprocess。 allocators_containers.containers_explained – 2009-08-13 13:58:12