简体   繁体   中英

boost interprocess : shared memory and stl types

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 (eg char*) instead of stl types?

Edit :

I tried with

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

and it works!

You should use

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM