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!darwin.sura.net!udel!intercon!psinntp!sunic!kth.se!hemul.nada.kth.se!d88-jwa
- From: d88-jwa@hemul.nada.kth.se (Jon WΣtte)
- Subject: Re: A malloc() built upon sbrk() on a Mac?
- Message-ID: <1993Jan27.164137.29669@kth.se>
- Sender: usenet@kth.se (Usenet)
- Nntp-Posting-Host: hemul.nada.kth.se
- Organization: Royal Institute of Technology, Stockholm, Sweden
- References: <BOORTZ.93Jan27115728@dunlop.sics.se>
- Distribution: comp
- Date: Wed, 27 Jan 1993 16:41:37 GMT
- Lines: 58
-
- In <BOORTZ.93Jan27115728@dunlop.sics.se> boortz@sics.se (Kent Boortz) writes:
-
- >1. Allocate a fixed stack space (this is the normal way
- > on a Mac, isn't it?)
-
- Yes. It is defaulted at 8k/24k depending on your machine.
-
- >2. Allocate with NewPtr() memory at the lowest address
- > in the application heap. This will be immediately
- > after the stack space.
-
- Tut-tut. The stack grows from top down to the heap limit.
- Pointers are shoved as far down as possible in the heap. In
- between lies handles that can move. MoveHHi tries to slam
- its argument handle to the top of the heap.
-
- >3. Implement sbrk() with SetPtrSize() on this memory area
- > and let malloc() take memory from this area.
-
- Bad Idea. SetPtrSize may move the block, which invalidates all
- your present pointers into it. Not to mention there might be another
- locked block (ptr or locked handle that isn┤t movehhid) in its way.
-
- >4. If SetPtrSize() fails I do a MaxApplZone() and try
- > again.
-
- Won┤t help; SetPtrSize WILL call MaxApplZone() and try again.
- Not to mention you should call it right after setting the amount
- of stack you need yourself, BEFORE calling InitGraf.
-
- >Any thought about this? Is there other ways of doing what I want?
-
- Grab all of the available memory minus a constant (for code
- resources etc) and a percentage (so increasing app heap size
- helps for the users)
-
- The keep your own sbrk() pointer that you just walk through your
- existing block. There is no better way.
-
- >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.
-
- Instead, use handles, and re-code your application to take advantage
- of this. Handles can grow completely independently of each other
- (well, almost) as long as you don't lock them. You have to be
- careful about locking down handles whenever you pass its dereference,
- or something derived from this reference, to the ToolBox.
-
- Cheers,
-
- / h+
- --
- -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
-
- What we need is a good GNU [...] licence manager implementation.
- -- Raphael Manfredi
-