tempMemBlock = (TemporaryMemoryHandle)TempNewHandle(size + sizeof(TemporaryMemoryBlock), &result); if (tempMemBlock && result == noErr) {
HLockHi((Handle)tempMemBlock);
tempPtr = (**tempMemBlock).data; if (clearMemory) memset(tempPtr, 0, size);
tempPtr = StripAddress(tempPtr);
/* keep track of the allocated blocks. */
(**tempMemBlock).nextBlock = theTemporaryMemory;
theTemporaryMemory = tempMemBlock;
}
# if !defined(SHARED_LIBRARY_BUILD) /* install an exit routine to clean up the memory used at the end. */ if (firstTime) {
atexit(&GC_MacFreeTemporaryMemory);
firstTime = false;
} # endif
return tempPtr;
}
staticvoid perform_final_collection(void)
{ unsigned i;
word last_fo_entries = 0;
/* adjust the stack bottom, because CFM calls us from another stack
location. */
GC_stackbottom = (ptr_t)&i;
/* try to collect and finalize everything in sight */ for (i = 0; i < 2 || GC_fo_entries < last_fo_entries; i++) {
last_fo_entries = GC_fo_entries;
GC_gcollect();
}
}
void GC_MacFreeTemporaryMemory(void)
{ # ifdefined(SHARED_LIBRARY_BUILD) /* if possible, collect all memory, and invoke all finalizers. */
perform_final_collection(); # endif
if (theTemporaryMemory != NULL) { # if !defined(SHARED_LIBRARY_BUILD) long totalMemoryUsed = 0; # endif
TemporaryMemoryHandle tempMemBlock = theTemporaryMemory; while (tempMemBlock /* != NULL */) {
TemporaryMemoryHandle nextBlock = (**tempMemBlock).nextBlock; # if !defined(SHARED_LIBRARY_BUILD)
totalMemoryUsed += GetHandleSize((Handle)tempMemBlock); # endif
DisposeHandle((Handle)tempMemBlock);
tempMemBlock = nextBlock;
}
theTemporaryMemory = NULL;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.