boost interprocess : shared memory and stl types
-
13-09-2019 - |
Question
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!
Solution
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.
OTHER TIPS
You should use
typedef boost::interprocess::basic_string<char> shared_string;
struct MyType
{
shared_string name;
shared_string description;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow