How to get Shared Object in Shared Memory

前端 未结 4 1361
Happy的楠姐
Happy的楠姐 2021-01-16 07:07

Our app depends on an external, 3rd party-supplied configuration (including custom driving/decision making functions) loadable as .so file.

Independently, it coopera

4条回答
  •  终归单人心
    2021-01-16 07:35

    The first thing to bear in mind when using shared memory is that the same physical memory may well be mapped into the two processes virtual address space as different addresses. This means that if pointers are used anywhere in your data structures, they are going to cause problems. Everything must work off an index or an offset to work correctly. To use shared memory, you will have to purge all the pointers from your code.

    When loading a .so file, only one copy of the .so file code is loaded (hence the term shared object).

    fork may also be your friend here. Most modern operating systems implement copy-on-write semantics. This means that when you fork, your data segments are only copied into separate physical memory when one process writes to the given data segment.

提交回复
热议问题