[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: |
Alejandro Forero Cuervo |
Subject: |
Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objects |
Date: |
Thu, 18 Dec 2008 14:52:52 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
> 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?
> 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.
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?
Alejo.
http://azul.freaks-unidos.net/
- [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
- Re: [Chicken-users] newbie: foreign pointers that depend on Scheme objects,
Alejandro Forero Cuervo <=