Its not clear from your code whether you meant boost::interprocess::string or std::string, but from my few hours boost::interprocess (rather frustrating...) experience, you want neither...
So, here's a
Quick guide for strings in boost::interprocess
First, you need to define a special string:
typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> my_string;
Second, sending app should use:
// (mshm is the managed_shared_memory instance from the question)
mshm.construct<my_string>( SOME_STRINGY_NAME )(
"Message to other process",
mshm.get_segment_manager());
Last, reading app should:
std::pair<my_string * , size_t > p= mshm.find<my_string>(SOME_STRINGY_NAME);
cout<< "got " << p.second << " strings " << endl;
cout<< "first string is->"<<p.first->c_str()<<endl;
Note: Reason for all this complexity is this.
Cheers
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…