Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!uw-beaver!ubc-cs!fornax!mcdonald From: mcdonald@fornax.UUCP (Ken Mcdonald) Newsgroups: comp.sys.mac.programmer Subject: How to do garbage collection in C Message-ID: <153@fornax.UUCP> Date: 1 Dec 89 19:34:29 GMT Organization: School of Computing Science, SFU, Burnaby, B.C. Canada Lines: 24 I'm programming an applica[tion which has need of a built-in garbage collector. Specifically, I need a garbage collector that can allocate arbitrarily-sized blocks, resize blocks, and do automatic reclamation of unused blocks--I think that mark-scan reclamation is best for my purposed, although if anyone knows of anything better, I'd appreciate hearing about it. (Note that I'm using the term "garbage collector" rather sloppily, to include the dynamic memory allocator as well.) Conceptually this is easy, I just use the Mac memory manager to allocate a large block, and then do all of my own allocation in it. The problem I'm facing right now is in trying to program the reclamation algorithm in C--in order to mark the unused blocks, I need to crawl along the stack, following out any pointers that happen to have been pushed onto the stack. This brings up several problems, namely: How to explicitly access C's stack; how to differentiate pointers from other data; how to determine when the end of the stack has been reached. I'm a novice C programmer, and would appreciate tips on these from people more skilled than myself. On the other hand, if anyone happens to have a garbage collector just lying around that would do everything I need, I wouldn't mind a copy of that! Thanks for all the help, netland . . . Ken McDonald {mcdonald@lccr.cs.sfu.ca}