Boost interprocess: cout a string variable when iterating through a map that references an object from a struct

后端 未结 3 967
孤街浪徒
孤街浪徒 2021-01-18 19:23

I\'m using boost::interprocess to share objects between processes. I have two files, a \"server.cpp\" that generates a struct object and passes the object into a map with an

3条回答
  •  渐次进展
    2021-01-18 19:43

    But for some reason the client executable throws a segmentation fault if I try to access a string rather than a float or an integer in the client.

    It looks like you are using std::string in your structure within the shared memory map. You cannot do this, since std::string allocates it's own memory which goes out of scope with boost::interprocess. You should try using the boost::interprocess::basic_string type in place of std::string. There is an example of how to use this in an interprocess map in the Boost documentation

    #include 
    

提交回复
热议问题