This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Jim Blandy <jimb@red-bean.com> writes: > I really think there ought to be graceful solutions to both of these > situations. Given the nature of garbage collection, Guile gives you a > powerful hooks into that. I don't know if this qualifies as graceful, but there is a simple minded alternative to the suggestion I gave in the previous letter if you want the C objects to point directly to other C objects, but still want to be able to use the garbage collector to keep track of references: Include a "handle" pointing back to the Scheme level object in every C struct. This way, C level objects can refer to each other directly by C pointers, but the garbage collector can still find the corresponding Scheme level wrapper objects (the smobs): struct foo { SCM handle; ... struct bar *bar; ... }; struct bar { SCM handle; ... }; The markfoo function then contains: scm_gc_mark (((struct foo *) SCM_CDR (obj))->bar->handle); (or return ((struct foo *) SCM_CDR (obj))->bar->handle;) /mdj