It might be a silly question but… I have two processes P1 and P2. Can P1 allocate easily an object O in a shared memory that would be seen for P2? (P1 passes to P2 a pointer to O using a pipe). Something like:
// P1
ptr1 = new SharedMemoryObject(); // object O
pipe.send(ptr1)
// P2
ptr = pipe.recieve()
// I have access to O now
I want to avoid serializing and piping the objects, I would like to create them in shared memory and pass pointers
Each process has its own address space which means that although a physical memory address may be shared between the two processes, this probably will correspond to different addresses in each process’s address space. This means that when designing object that will exist in shared memory you MUST ensure they use offsets or indexes and not pure pointers.
Sharing memory will create synchronisation issues which can cause no end of problems, so unless you really have to, I will advise you to use the pipe route in preference to shared memory.