Distinct address spaces for pointers
When you are sharing values, everything is clear. For example when put a float
value such as 1234.5
in the shared memory, in the other side you can read it simply.
But when you are sharing complex objects (which contain pointers) there is an important problem. The address space of two processes are completely different and distinct. For example you can not put a std::vector
object in the shared memory, because it has a pointer to its data in process1 e.g. 0x1ABF212
and this number is meaningless for process2.
So, you have to write down the items of std::vector
one by one in the shared memory. Read about Serialization technique to share complex data.
Also, if you're insisting to share complex object as a unique object between processes, you can make those objects with specific memory allocators.
AFAIK Boost.Interprocess
has that allocators. It manages shared memory and makes pointers inside the shared memory which is meaningful for both processes.
Sorry for ambiguity, My bad English