Data Structures in Shared Memory

Mike_Light mlight at hp-ptp.HP.COM
Sat Feb 10 08:48:30 AEST 1990


Tried to e-mail this to you but it bounced --

>I'm trying to use shared memory (shmctl(), shmat() etc etc) to store
>some data that will be accessed by a number of processes. It all works fine
>with the obvious restriction that the data structure so stored must be 'flat'
>ie no pointers, as these would then most likely point to an address in another
>process' address space. Has anyone done any work on getting non-'flat' data
>structures (ie with pointers to other areas of the same shared memory 
>segment) to work? 

There are two ways to do it, but both face porting issues (if that
concerns you).

1. Store "byte offsets" where you would normally store a pointer.
   Every process has to calculate its own pointer like so:

   pointer = (char *)shmem_addr + byte_offset;


2. Every process attaches the shared memory at the same address.
   This solution is hideously dependent on the size of the processes
   and the method of generating correct addresses on the particular
   machine.  Such code is usually unportable as h*ll.

Enjoy!
-----------------------------------------------------------------------
 Mike Light  HP Industrial Applications Center - mlight at hpiala9.HP.COM
-----------------------------------------------------------------------



More information about the Comp.unix.wizards mailing list