[plt-scheme] Re: scheme_weak_reference and MZ_PRECISE_GC

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Sep 9 18:45:12 EDT 2008

At Tue, 09 Sep 2008 19:09:54 +0200, David Hansen wrote:
> On Tue, 9 Sep 2008 10:22:18 -0600 Matthew Flatt wrote:
> 
> > At Tue, 09 Sep 2008 17:59:42 +0200, David Hansen wrote:
> >> I want a mapping 
> >> 
> >> <some C pointer from another lib> -> <Scheme_Object* that wraps around
> >> the C pointer + some possible other data>.
> >
> > That's simply a hash table from integers (representing C pointers) to
> > Scheme objects.
> >
> > If that's it, there's no need for anything like weak references. Is
> > there more to the problem?
> 
> Well, sometimes it's that easy :)  Thank you very much.  Last question
> for now:  How do I store weak values?  Using a weak box?

Just to make sure I understand: what do you mean by "weak values"?

Do you mean, for example, that the Scheme objects in the above table
should be collectable even while the C object is still allocated
(perhaps because the table of wrappers is really just a cache)?

In that case, yes, a weak box can be used for the value of the hash
table, and when you look up a box from the table, you'll have to treat
an empty box the same as not being in the table.

Matthew



Posted on the users mailing list.