Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!kunivv1!ge From: ge@kunivv1.sci.kun.nl (Ge' Weijers) Newsgroups: comp.sys.mac.programmer Subject: Re: How to do garbage collection in C Message-ID: <555@kunivv1.sci.kun.nl> Date: 4 Dec 89 10:15:30 GMT References: <153@fornax.UUCP> Organization: University of Nijmegen, The Netherlands. Lines: 32 About your GC problem. There is still a way to do it if you want, although Your C source code needs to be adapted for this method. What you do is to allocate a root stack, that is used by the garbage collector to find references on. If you call the garbage collector (or a routine that might call the garbage collector) you have to save and restore root pointers to this stack. An example: any_routine(HeapPointer p1) { HeapPointer p2 = .....; /* a C pointer into the GC heap */ SavePointer(p1); SavePointer(p2); RoutineCallingGC(); /* p1 and p2 might point to garbage. restore them */ p2 = GetPointer(); p1 = GetPointer(); } This is not the ultimate in efficiency, but if you implement SavePointer and GetPointer using macros it might have a reasonable performance. Also check for stack overruns. It's the only way I know of to implement a compacting GC for C. Sigh. Ge' Weijers Ge' Weijers Internet/UUCP: ge@cs.kun.nl Faculty of Mathematics and Computer Science, (uunet.uu.net!cs.kun.nl!ge) University of Nijmegen, Toernooiveld 1 6525 ED Nijmegen, the Netherlands tel. +3180612483 (UTC-2)