开发者

Getting offset_ptr of object in shared memory

开发者 https://www.devze.com 2023-01-19 07:36 出处:网络
How can i access the offset_ptr of the object which is created in the shared memory? segment = new managed_shared_memory(create_only, \"MySharedMemory\", segmentSize);

How can i access the offset_ptr of the object which is created in the shared memory?

segment = new managed_shared_memory(create_only, "MySharedMemory", segmentSize);  
line = 开发者_运维知识库segment->construct<Line>("Line1")("line");

I want to access of offset_ptr for Line object..


First, you need to declare the offset pointer with your Line type:

boost::interprocess::offset_ptr<Line> offset_p;

Second, you assign it:

offset_p = line;

Now, offset_p holds an offset from from line to itself, so you can get a pointer to line and use it in any process like this:

draw_line( offset_p.get() );
0

精彩评论

暂无评论...
验证码 换一张
取 消