The first thing to consider when using shared memory is that the same physical memory can be mapped to the virtual address space of two processes as different addresses. This means that if pointers are used anywhere in your data structures, they will cause problems. Everything should work with an index or offset to work properly. To use shared memory, you will have to clear all pointers from your code.
When you download the .so file, only one copy of the code for the .so file is downloaded (hence the term shared object).
fork can also be your friend here. Most modern operating systems implement copy-on-write semantics. This means that when you fork , your data segments are copied only to a separate physical memory, when one process writes to this data segment.
doron source share