[comp.unix.wizards] Data Structures in Shared Memory

everson@CompSci.Bristol.AC.UK (Phill Everson ) (02/06/90)

Machine: SparcStation 1
OS: SunOS 4.03

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? 

Any pointers, hints etc would be appreciated - if you email I will post a
summary if worthwhile. Thanks for your time.

Phillip G. Everson
Senior Software Engineer                  Medical Imaging
Philips Radiotherapy Systems              Dept. Computer Science
Horfield Road, Bristol, UK                Bristol University, UK

mlight@hp-ptp.HP.COM (Mike_Light) (02/10/90)

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@hpiala9.HP.COM
-----------------------------------------------------------------------

brnstnd@stealth.acf.nyu.edu (02/15/90)

What happened to using arrays and indices? Have C programmers forgotten
what pointers mean? :-)

---Dan