发送端: #include#include #include using namespace std;#include #include #include using namespace boost::interprocess;int num = 0;mapped_region *mp_r;void funs(){ while (1) { num ++; memcpy(mp_r->get_address(), &num, sizeof(int)); mp_r->get_address(); Sleep(500); } }int main(int argc, char*argv[]){ shared_memory_object share_obj(create_only, "named_obj", read_write); share_obj.truncate(sizeof(int)); mp_r = new mapped_region(share_obj, read_write); std::thread th(funs); th.detach(); getchar(); return 0;}
接收端: #include#include #include using namespace std;#include #include #include using namespace boost::interprocess;mapped_region* mp_r;void fung(){ while (1) { int num = 0; memcpy(&num, static_cast (mp_r->get_address()), sizeof(int)); cout< <