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 theCompactMemfunction to compact the current heap zone manually.
FUNCTION CompactMem (cbNeeded: Size): Size;
cbNeeded- The size, in bytes, of the block for which
CompactMemshould attempt to make room.DESCRIPTION
TheCompactMemfunction 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 leastcbNeededfree bytes or has compacted the entire zone.The
CompactMemfunction 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 constantmaxSizefor the largest contiguous block possible in the 24-bit Memory Manager:
CONST maxSize = $800000; {maximum size of a block}SPECIAL CONSIDERATIONS
BecauseCompactMemmoves memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit forCompactMemare
Registers on entry D0 Size of block to make room for
Registers on exit D0 Size of largest allocatable block The
CompactMemfunction 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 wordSYSas the second argument to the routine macro, as follows:
_CompactMem ,SYSRESULT CODES
noErr 0 No error