Handling pointer addresses

Started by
1 comment, last by brv 22 years, 2 months ago
I have 2 processes talking to each other. Process A allocates objects and sends the addresses of these objects to process B. Process B sends the address of an object to process A which invokes methods on this object. BUT sometimes, the addresses turn out to be invalid causing a coredump. How best can I handle this ?
Bijal Vora
Advertisement
You can''t do this, as the OS is free to do whatever it likes to cause these addresses to become invalid, as you are discovering. An address is generally only guaranteed to remain valid within a single process space. If you wish to communicate across processes, you must get the OS to act as an intermediary between them. That''s what technologies such as shared memory, RPC, DCOM, etc, are for. You didn''t state exactly what you are doing, but I''m surprised it works at all.

--
1st law of programming: Any given program, when running, is obsolete.
If you''re using *NIX, have a look at mmap().
A quick lookup in MSDN gave me the CSharedFile class.
Further searching gave CreateSharedMemory(), AllocateSharedMemory() and FreeSharedMemory(), as well as VirtualAlloc() and VirtualAllocEx()
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement