Carbon


CompactMem

Header: MacMemory.h Carbon status: Supported

Compacts the current heap zone.

Size CompactMem (
    Size cbNeeded
);
Parameter descriptions
cbNeeded

The size, in bytes, of the block for which CompactMem should attempt to make room.

function result

The size, in bytes, of the largest contiguous free block available after compacting the heap zone. CompactMem does not actually allocate that block.

DISCUSSION

The Memory Manager automatically compacts the heap when a memory request fails. However, you can use the CompactMem function to compact the current heap zone manually.

CompactMem compacts the current heap zone not by purging blocks, but rather by moving unlocked, relocatable blocks down until they encounter nonrelocatable blocks or locked, relocatable blocks. CompactMem continues compacting until it either finds a contiguous block of at least cbNeeded free bytes or compacts the entire zone.

To compact the entire heap zone, call CompactMem(maxSize).

Call the function MemError to get the result code. See “Result Codes”.

Because CompactMem moves memory, you should not call it at interrupt time.

AVAILABILITY

Supported in Carbon. Available in Carbon 1.0.2 and later when running Mac OS 8.1 or later.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)