Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Memory /
Chapter 2 - Memory Manager / Memory Manager Reference
Memory Manager Routines / Managing Relocatable Blocks


MoveHHi

If you plan to lock a relocatable block for a short period of time, use the MoveHHi procedure, which moves the block to the top of the heap and thus helps prevent heap fragmentation.

PROCEDURE MoveHHi (h: Handle);
h
A handle to a relocatable block.
DESCRIPTION
The MoveHHi procedure attempts to move the relocatable block referenced by the handle h upward until it reaches a nonrelocatable block, a locked relocatable block, or the top of the heap.

WARNING
If you call MoveHHi to move a handle to a resource that has its resChanged bit set, the Resource Manager updates the resource by using the WriteResource procedure to write the contents of the block to disk. If you want to avoid this behavior, call the Resource Manager procedure SetResPurge(FALSE) before you call MoveHHi, and then call SetResPurge(TRUE) to restore the default setting.
By using the MoveHHi procedure on relocatable blocks you plan to allocate for short periods of time, you help prevent islands of immovable memory from accumulating in (and thus fragmenting) the heap.

Do not use the MoveHHi procedure to move blocks you plan to lock for long periods of time. The MoveHHi procedure moves such blocks to the top of the heap, perhaps preventing other blocks already at the top of the heap from moving down once they are unlocked. Instead, use the ReserveMem procedure before allocating such blocks, thus keeping them in the bottom partition of the heap, where they do not prevent relocatable blocks from moving.

If you frequently lock a block for short periods of time and find that calling MoveHHi each time slows down your application, you might consider leaving the block always locked and calling the ReserveMem procedure before allocating it.

Once you move a block to the top of the heap, be sure to lock it if you do not want the Memory Manager to move it back to the middle partition as soon as it can. (The MoveHHi procedure cannot move locked blocks; be sure to lock blocks after, not before, calling MoveHHi.)

Note
Using the MoveHHi procedure without taking other precautionary measures to prevent heap fragmentation is useless, because even one small nonrelocatable or locked relocatable block in the middle of the heap might prevent MoveHHi from moving blocks to the top of
the heap.
SPECIAL CONSIDERATIONS
Because the MoveHHi procedure moves memory, you should not call it at interrupt time.

Don't call MoveHHi on blocks in the system heap. Don't call MoveHHi from a desk accessory.

ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit for MoveHHi are
Registers on entry
A0Handle to move
Registers on exit
D0Result code

RESULT CODES
noErr0No error
nilHandleErr-109NIL master pointer
memLockedErr-117Block is locked

Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996