home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!saimiri.primate.wisc.edu!caen!uwm.edu!spool.mu.edu!darwin.sura.net!newsserver.jvnc.net!gmd.de!Germany.EU.net!mcsun!chsun!bernina!bernina!neeri
- From: neeri@iis.ethz.ch (Matthias Neeracher)
- Subject: Re: A malloc() built upon sbrk() on a Mac?
- In-Reply-To: boortz@sics.se's message of Wed, 27 Jan 1993 10:57:28 GMT
- Message-ID: <NEERI.93Jan27192832@iis.ethz.ch>
- Sender: news@bernina.ethz.ch (USENET News System)
- Organization: Integrated Systems Laboratory, ETH, Zurich
- References: <BOORTZ.93Jan27115728@dunlop.sics.se>
- Distribution: comp
- Date: Wed, 27 Jan 1993 18:28:32 GMT
- Lines: 76
-
- In article <BOORTZ.93Jan27115728@dunlop.sics.se>, boortz@sics.se (Kent Boortz) writes:
- > I have a malloc() replacement that I want to port to Mac.
- > It assumes a continuous memory area and a upper bound
- > moved by the Unix sbrk() call.
-
- > What I came to think of is this:
-
- > 1. Allocate a fixed stack space (this is the normal way
- > on a Mac, isn't it?)
-
- Yes.
-
- > 2. Allocate with NewPtr() memory at the lowest address
- > in the application heap. This will be immediately
- > after the stack space.
-
- No. This is *opposite* the stack.
-
- > 3. Implement sbrk() with SetPtrSize() on this memory area
- > and let malloc() take memory from this area.
-
- Bad idea. This assumes that nobody ever does a NewPtr or allocates too many
- handles in your heap after you have started your malloc() (I broke a version of
- Lightspeed Pascal which had this assumption a few years ago).
-
- > 4. If SetPtrSize() fails I do a MaxApplZone() and try
- > again.
-
- Useless. If there is any way to make SetPtrSize succeed, the Memory Manager
- will make it succeed. If you allocate a fixed size stack, you should call
- MaxApplZone anyway.
-
- > This way my "Unix" memory handling will grow from low application
- > heap address to high and normal mac allocation will grow from
- > high memory address to low.
-
- Unfortunately, "normal" Mac allocation isn't all handles (And handles are not
- allocated high to low, but that's besides the point).
-
- > My problem is to do (2) because normally I can't tell the mac memory
- > manager where I want to take memory.
-
- Actually (2) was the single most workable point in your proposal. Simply
- calling NewPtr will ensure a best effort from the Memory Manager to place your
- memory as low as possible.
-
- >A solution to that could be:
-
- > AllocMem = NewPtr(MaxMem(&any));
- > SetPtrSize(AllocMem,size_wanted);
-
- No especially good idea, I'm afraid. In the presence of locked handles, this
- might be quite counterproductive.
-
- > Any thought about this? Is there other ways of doing what I want?
-
- Frankly, I get the impression that you are not very experienced with Macintosh
- memory management, which makes me wonder why you think you need that malloc()
- replacement in the first place.
-
- Maybe you might want to check out Tim Endres' malloc package, which is at
- ftp.msen.com, pub/mac/src/icemalloc.hqx. I have no actual experience with it,
- but as it was already written for the Mac, it certainly doesn't contain any
- sbrks().
-
- > Is there any way of doing mmap() on a mac?
-
- This probably depends on the model and the System version. It *might* work
- under A/UX.
-
- Matthias
-
- -----
- Matthias Neeracher neeri@iis.ethz.ch
- "You must have picked up that copy of Scarlett instead of Inside Mac
- when you tried to find the right call..." -- Keith Rollin
-