[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objec
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objects |
Date: |
Thu, 18 Dec 2008 15:28:31 +0100 |
On Thu, Dec 18, 2008 at 2:52 PM, Alejandro Forero Cuervo
<address@hidden> wrote:
>> To retain a safe reference to a Scheme-level object from C
>> can only be done via GC-roots, otherwise the reference will be lost on
>> the next GC.
>
> What happens if your Scheme-level object is only referenced (through a
> GC-root) from the C-level object and the C-level object is *only*
> referenced from the Scheme-level object? Do we not leak memory?
Then you'd have a circular reference - this will indeed not be reclaimed.
>
>> Of course, any references to C data (which may refer to Scheme data
>> via GC-roots) are not seen by the GC or finalization mechanism, so
>> will not "loop" into that direction.
>
> You mean "any references inside C data", right? I see what you're
> saying.
References to C data-structures which in turn refer to Scheme data
(without a GC root). I think this is probably confusing, because it's
obvious.
>
> I think we should have some structure "weaker" than GC-root that
> serves this purpose of allowing C-level objects to reference
> Scheme-level objects but which doesn't have the "never GC this"
> semantics. The GC-roots should use this structure but also have the
> stronger property of never being collected, even if they are not
> reachable from Scheme-level objects.
>
> The way I think it would make sense to do this would be the following.
> If I receive a c-pointer to some structure that can hold a pointer, I
> use a record that wraps the c-pointer and *always* refer to it through
> the structure. Then, when I set something inside of the c-pointer to
> point to a Scheme-object foo, I:
>
> 1. Create a new instance of the structure-weaker-than-a-GC-root, set
> it to foo and store a pointer to that in the C data.
>
> 2. Set an attribute in the record to foo, so that the GC code will
> know that it can't collect foo yet.
>
> What do you think?
I'm not sure I can follow your example completely (I always get quickly
confused with these scenarios), but I understand the "weak"/"finalizable"
GC-root suggestion. I have to think more about it, but it should be
possible.
cheers,
felix
- [Chicken-users] newbie: foreign pointers that depend on Scheme objects, Alejandro Forero Cuervo, 2008/12/15
- [Chicken-users] newbie: questions about set-finalizer!, Alejandro Forero Cuervo, 2008/12/15
- Re: [Chicken-users] newbie: questions about set-finalizer!, felix winkelmann, 2008/12/16
- Re: [Chicken-users] newbie: questions about set-finalizer!, felix winkelmann, 2008/12/17
- Re: [Chicken-users] newbie: questions about set-finalizer!, Alejandro Forero Cuervo, 2008/12/20
- Re: [Chicken-users] newbie: questions about set-finalizer!, felix winkelmann, 2008/12/21
- Re: [Chicken-users] newbie: questions about set-finalizer!, felix winkelmann, 2008/12/22
- Re: [Chicken-users] newbie: questions about set-finalizer!, felix winkelmann, 2008/12/22
Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objects, felix winkelmann, 2008/12/18