PurgeSpace
PurgeSpace
Check free space after a purge (without purging) long *totalSize ; receives total bytes after purge
long *contigSize ; receives size of largest block after purge
PurgeSpace is a quick way to check heap status as if a general purge were to occur. It does not actually perform the purge.
totalSize is the address of a long. Upon return, it will contain the total
number of bytes that would be available if a purge were to take place
(the current free space plus any space gained by purging).
contigSize is the address of a long. Upon return, it will contain the size, in
bytes of the largest block that would be available if a purge were to
take place.
Notes: PurgeSpace is an efficient quick check to make before allocating a large block of memory. Since it does not actually purge any blocks, there will be
no time lost purging and then regenerating purged blocks.
The MaxBlock function is similar in that it is a quick check for potentially available space, but for a hypothetical compaction, rather than a
conjectural purge. A typical sequence before allocating a large block might
look like:
long bytesNeeded, totalBytes, contigBytes;
if ( MaxBlock() < bytesNeeded ) { /* compacting enough?*/
if ( contigBytes < bytesNeeded) { /* purging enough? */
. . . allocation is very likely to fail . . .
}
}
myHandle = NewHandle( bytesNeeded ); /* try anyway */ if ( myHandle == 0 ) {
. . . allocation failed . . .
}
Note that the combination of compacting and purging that takes place when
a block is actually allocated may exceed the larger of the values returned by
MaxBlock or PurgeSpace. Furthermore, any space made available by a custom grow-zone procedure (see SetGrowZone) is not taken into consideration by either call, so you may need to call PurgeMem as a last
resort, anyway.