[comp.sys.mac.programmer] MoveHHi or NewPtr? Which end of heap?

oster@well.sf.ca.us (David Phillip Oster) (12/03/90)

In article <1990Nov30.013939.18568@midway.uchicago.edu> fri0@quads.uchicago.edu (Christian E. Fritze) writes:
>I've got ~75K of sound resources which I load into memory early during startup
>of my application.
Since they are already resources, it is more convenient to do a
	MoveHHi(), HLock() than it is to read them in,
	NewPtr(GetHandleSize()) them, BlockMove() them, and
DetachResource() them.

Just remember to do a SetApplLimit(MaxApplZone()) early in your program so
MoveHHi() puts them in the right place.
-- 
-- David Phillip Oster - At least the government doesn't make death worse.
-- oster@well.sf.ca.us = {backbone}!well!oster

wdh@well.sf.ca.us (Bill Hofmann) (12/03/90)

In article <1990Nov30.013939.18568@midway.uchicago.edu> fri0@quads.uchicago.edu (Christian E. Fritze) writes:
>I've got ~75K of sound resources which I load into memory early during startup
>of my application. These resources are accessed continually during operation
>of the app, so I will lock them down in memory for use.
>
>Question: Is it preferable to lock these away high (after a MoveHi(hndl)) or
>instead to try and allocate a nonrelocatable block at the beginning of the
>heap with NewPtr()? Which end of the heap is better? Many thanks.\

The answer is, whichever produces the least fragmentation.  Using a resource
(which gets loaded in as a handle, BTW), and MoveHHi/HLock seems to be a bit
better, since typically, if you have a separate segment for your init code, 
you'll UnloadSeg it when you're done, but then you'll leave a hole in the
heap before your non-reloc block holding the sounds.  Of course, MoveHHi
won't move a reloc block above a locked block if one's in the middle of the 
heap.  When I run into this kind of question, the way I approach it is to
carefully step through my init code with MacsBug or The Debugger or TMON
and watch what's going on, and adjust code to produce the desired results.

-Bill Hofmann