Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!cca!mirror!datacube!ftw
From: ftw@datacube.UUCP
Newsgroups: comp.unix.wizards
Subject: Re: Motorola shared memory questions
Message-ID: <106600019@datacube>
Date: Mon, 30-Nov-87 10:46:00 EST
Article-I.D.: datacube.106600019
Posted: Mon Nov 30 10:46:00 1987
Date-Received: Fri, 4-Dec-87 04:16:44 EST
References: <106600017@datacube>
Lines: 40
Nf-ID: #R:datacube:106600017:datacube:106600019:000:1665
Nf-From: datacube.UUCP!ftw    Nov 30 10:46:00 1987


Just wanted to take a moment and thank the folks who responded to my
questions about shared memory on Sys V.  To summarize:

When I call shmget(), I should grab as much memory as I can, and that size
arg. should be a multiple of a "shared memory block size".

When I call shmat() for the first time, use a NULL arg. for the attach
address; shmat() gives out virtual addresses that are always (shared memory)
block aligned, even if the corresponding shmat() asked for a smaller chunk
of memory.

Successive calls to shmat() should have an arg of whatever the first shmat()
returned for the virtual address, plus the number of bytes requested so far.
This ensures a nice, flat virtual address space.

The Sun scheme of valloc()/mmap() isn't applicable because shmat() needs
an address that's not already in use (allocated my malloc()).  Almost
everyone who responded pointed this out.

A virtual address given to shmat() MUST always be (shared memory) block
aligned.  If you specify through the third arg that you don't want shmat()
to align the address for you, and you don't give it one that is already
properly aligned, the call will fail.

Jonathan Creighton (pyrnj!oracle!jcreight) has an interesting suggestion:
he suggests that I choose a virtual address that is closer to the midpoint
between the current stack and heap, so that I won't run out of space for
malloc() or lotsa nested funtion calls.

Thank you all for the help!



				Farrell T. Woods 

Datacube Inc. Systems / Software Group	4 Dearborn Rd. Peabody, Ma 01960
VOICE:	617-535-6644;	FAX: (617) 535-5643;  TWX: (710) 347-0125
INTERNET: ftw@datacube.COM
UUCP: {rutgers, ihnp4, mirror}!datacube!ftw