[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: GC question
From: |
Erik Sandberg |
Subject: |
Re: GC question |
Date: |
Thu, 18 Aug 2005 12:08:01 +0200 |
User-agent: |
KMail/1.8.1 |
On Thursday 18 August 2005 11.25, Han-Wen Nienhuys wrote:
> Erik Sandberg wrote:
> > class A {
> > SCM b_;
> > A() { b_ = get_b (); scm_gc_protect_object (b_); }
> > ~A() { scm_gc_unprotect_object (b_); }
> > ...
> > };
> >
> > Now if a third smob C contains an A object, as in
> >
> > class C {
> > A a_;
> > ...
> > DECLARE_SMOBS (C);
> > };
> >
> > .. then A's gc_unprotect will be called during the gc sweep.
> >
> > Is my problem related to the smob macros in Lilypond? (if not, I should
> > ask on guile-user instead).
>
> do the following:
>
> make A::protect() and A::unprotect().
>
> In C::C call A::unprotect, and use C::mark to mark the smob. You will
> also need machinery to make sure unprotect() isn't called if the B is no
> longer protected.
The problem is that A and B are created implicitly by macros, and C can
contain more than one such macro. Hence, it's difficult for the creator of C
to know what to mark. I think it's partially solvable by adding even more
disgusting macros (creating a static linked list of relative pointers to
members to be marked by mark_smob), but I think I'll stick to a different
inefficient & simple solution for now.
--
Erik