home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!agate!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!sics.se!boortz
- From: boortz@sics.se (Kent Boortz)
- Subject: A malloc() built upon sbrk() on a Mac?
- Message-ID: <BOORTZ.93Jan27115728@dunlop.sics.se>
- Sender: news@sics.se
- Organization: Swedish Institute of Computer Science, Kista
- Distribution: comp
- Date: Wed, 27 Jan 1993 10:57:28 GMT
- Lines: 40
-
-
-
- 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?)
- 2. Allocate with NewPtr() memory at the lowest address
- in the application heap. This will be immediately
- after the stack space.
- 3. Implement sbrk() with SetPtrSize() on this memory area
- and let malloc() take memory from this area.
- 4. If SetPtrSize() fails I do a MaxApplZone() and try
- again.
-
- 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. The collision of memory will still
- be handled by the memory manager.
-
- My problem is to do (2) because normally I can't tell the mac memory
- manager where I want to take memory. A solution to that could be:
-
- AllocMem = NewPtr(MaxMem(&any));
- SetPtrSize(AllocMem,size_wanted);
-
- Any thought about this? Is there other ways of doing what I want?
-
- Is there any way of doing mmap() on a mac? I have some large allocated
- blocks that sometimes has to grow, and many small blocks. This sometimes
- lead to big holes in the malloc memory area. If I could place these blocks
- sparse they could grow and shrink without moving.
-
- /kgb
- --
- Kent Boortz
- boortz@sics.se
-