[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
The GC and Guardians
From: |
Han-Wen Nienhuys |
Subject: |
The GC and Guardians |
Date: |
Tue, 8 Jul 2003 01:21:43 +0200 |
address@hidden writes:
> int foo(...)
> {
> SCM mysmob;
>
> mysmob = create_mysmob(...);
> scm_define(scm_str2symbol(...), mysmob);
>
> return;
> }
>
> My understanding is that since the SMOB bound to the top level
> environment, the garbage collector should not destroy it since
> its referenced by the top root. I do later undefine it when I no
> longer care about it.
Yup, this looks ok.
> Also, on an unrelated problem, I want to be able to create a C
> structure and have it reference non-immediate SCM data, but I
> cannot turn this C structure into a SMOB. Unfortunately the folks
> using my code may not be happy dealing with guile
> directly. Should I use a guardian on the SCM data like so?
>
> foo_t *foo_create(void)
> {
> foo_t *foo = create_foo();
> SCM guardian;
>
> foo->mylist = SCM_EOL;
> guardian = scm_make_guardian(...);
>
> scm_apply(....); /* protect foo->mylist with the guardian procedure */
>
> return foo;
> }
I don't know anything about guardians, but why don't you simply use
scm_gc_(un)protect_object()?
--
Han-Wen Nienhuys | address@hidden | http://www.xs4all.nl/~hanwen