I have shared Memory like this
struct MEMORY {
char * type;
int number;
}
now in code I make it shared everything works probably but other process can't see what pointer points to how can I use pointer in shared memory?
I have shared Memory like this
struct MEMORY {
char * type;
int number;
}
now in code I make it shared everything works probably but other process can't see what pointer points to how can I use pointer in shared memory?
You need to make sure that the shared memory is attached at the same address in the address space of all the processes. Otherwise, as you can imagine, the pointer values end up meaning different things in different processes.
What are you using for shared memory? mmap or shm? It is the first argument in the mmap call.
If you cannot assure same address space in all processes, the other way to go is to us offsets only. Each process simply offsets from the base address where the shared memory is attached.
EDIT: Ah ... maybe what you are saying is that "char* type" is some arbitrary pointer. Remember that the other processes can only see what is in the shared memory. All other memory locations (pointer values) are inaccessible. So, for this pointer to work, it needs to be to something that is in shared memory, not just any arbitrary pointer. That, and you need to assure that the shared memory is attached at the same address in all processes.