Some routines for the Macintosh OS port of the Hans-J. Boehm, Alan J. Demers garbage collector.
<Revision History>
11/22/94 pcb StripAddress the temporary memory handle for 24-bit mode. 11/30/94 pcb Tracking all memory usage so we can deallocate it all at once. 02/10/96 pcb Added routine to perform a final collection when unloading shared library.
by Patrick C. Beard.
*/ /* Boehm, February 15, 1996 2:55 pm PST */
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 ist noch experimentell.