Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!snorkelwacker!usc!brutus.cs.uiuc.edu!wuarchive!decwrl!ucbvax!hplabs!hp-ses!hp-ptp!mlight From: mlight@hp-ptp.HP.COM (Mike_Light) Newsgroups: comp.unix.wizards Subject: Re: Data Structures in Shared Memory Message-ID: <1740001@hp-ptp.HP.COM> Date: 9 Feb 90 21:48:30 GMT References: <1322@csisles.Bristol.AC.UK> Organization: HP Pacific Technology Park - Sunnyvale, Ca. Lines: 28 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 -----------------------------------------------------------------------