Important: The information in this document is obsolete and should not be used for new development.
CompactMem
The Memory Manager compacts the heap for you when you make a memory request that it can't fill. However, you can use theCompactMem
function to compact the current heap zone manually.
FUNCTION CompactMem (cbNeeded: Size): Size;
cbNeeded
- The size, in bytes, of the block for which
CompactMem
should attempt to make room.DESCRIPTION
TheCompactMem
function compacts the current heap zone by moving unlocked, relocatable blocks down until they encounter nonrelocatable blocks or locked, relocatable blocks, but not by purging blocks. It continues compacting until it either finds a contiguous block of at leastcbNeeded
free bytes or has compacted the entire zone.The
CompactMem
function returns the size, in bytes, of the largest contiguous free block for which it could make room, but it does not actually allocate that block.To compact the entire heap zone, call
CompactMem(maxSize)
. The Memory Manager defines the constantmaxSize
for the largest contiguous block possible in the 24-bit Memory Manager:
CONST maxSize = $800000; {maximum size of a block}SPECIAL CONSIDERATIONS
BecauseCompactMem
moves memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit forCompactMem
are
Registers on entry D0 Size of block to make room for
Registers on exit D0 Size of largest allocatable block The
CompactMem
function compacts the current heap zone. If you want to compact the system heap zone rather than the current heap zone, set bit 10 of the routine trap word. In most development systems, you can do this by supplying the wordSYS
as the second argument to the routine macro, as follows:
_CompactMem ,SYSRESULT CODES
noErr 0 No error