views:

620

answers:

2

I have a simple struct :

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

and I'm putting it in a shared memory :

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

If the two applications communicating with the shared memory are built using different version of Visual Studio (different version of stl implementation) should I put native types in the shared memory (e.g. char*) instead of stl types?

Edit :

I tried with

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

and it works!

+2  A: 

Boost.Interprocess often offers replacements for STL types, for usage in shared memory. std::string, especially when just a member of a struct, will not be accessible from another process. Other people also had such a problem.

gimpf
Yeah, see this section of the documentation: http://www.boost.org/doc/libs/1_39_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.containers_explained
Jason
+1  A: 

You should use

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