简体   繁体   中英

boost c++ offset pointers in memory mapped files

I want to implement a memory mapped file. With reference to: http://www.boost.org/doc/libs/1_66_0/doc/html/interprocess/sharedmemorybetweenprocesses.html#interprocess.sharedmemorybetweenprocesses.mapped_file ! i now understand the basics of memory mapped file and implementation. However i was not able to find a through example of usage of offset pointer with memory mapped file. Can anybody throw some light on this and provide small code snippet if possible?

  1. The usage of offset pointer is only needed when you place objects having pointer objects in shared memory.

  2. For instance: if you place the below structure in shared memory then you may not able to access the second raw pointer member in the process (who did not create it) as virtual address is different for each process.

    struct example { int a, int* b, float c };

  3. Solution - To use the structure in different processes, you can replace the second member with offset_ptr.

    struct example { int a, offset_ptr b, int c };

ref: http://www.boost.org/doc/libs/1_38_0/doc/html/interprocess/offset_ptr.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM