Itβs not clear from your code whether boost :: interprocess :: string or std :: string made sense, but from my few hours boost :: interprocess (pretty unpleasant ...) experience, you donβt want ...
So here a
Quick guide for strings in boost :: interprocess
First you need to define a special line:
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;
Secondly, when sending the application, you 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());
Finally, the reader application 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. The reason for all this complexity is this .
Greetings
source share