guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GLOCs are going away.


From: Dirk Herrmann
Subject: Re: GLOCs are going away.
Date: Fri, 27 Jul 2001 19:03:20 +0200 (MEST)

On 26 Jul 2001, Michael Livshin wrote:

> Marius Vollmer <address@hidden> writes:
> 
> > Dirk Herrmann <address@hidden> writes:
> > 
> > > However, I just realized that we _could_ easily provide weak pairs:  
> > > Since Michael has extracted the GC flags from the cells, bit #0 of a
> > > pair's cdr is always 0 (it was used to store the mark bit for pairs during
> > > gc).  This bit could be used to indicate weak pairs.
> > 
> > Interesting idea.  Is there something fundamental wrong with the
> > current weak vectors and hashtables?
> 
> well, not as such.
> 
> one can make the case that given weak pairs and guardians you can
> implement weak dictionaries in pure Scheme, thus not needing the
> primitive support for weak vectors/hashes.
> 
> but:
> 
> if your dictionary implementation is vector-based (like the one in
> Guile), then the current primitively-implemented weak hash tables are
> better, since they have no memory overhead (compared to non-weak
> ones).
> 
> if your dictionary implementation is different, then it's a different
> story.
[...]
> is there any interesting use for weak pairs besides implementing weak
> dictionaries?

I can't tell there are many of them, but:  When I worked on the
environments, I needed a list of weak objects in order to store the weak
observers for each environment.  Since guile does not have weak pairs, I
had to misuse a weak hashtable to emulate a weak list.

With respect to weak dictionaries:  Dictionaries can be implemented in a
lot of different ways:  Trees, hash tables etc.  For each variant, there
are in turn a lot of implementation possibilities.  Jay Glascoe has
implemented a set of auto resizing hash tables, including a very generic
solution, where the hash function and the equality predicate can be
user-specified.

Without weak pairs, for every dictionary implementation one has to provide
the corresponding weak implementation.  Or, even worse, several weak
implementations:  When do you want your dictionary entry to
disappear?  Do you want it to disappear if the key gets collected, or do
you also want the entry to disappear if there are no more references to
the value, i. e. the hash table itself should not protect the value?  The
implementation has to be done on the C level and the code has to interact
with the garbage collector.

Weak pairs allow users to implement their own weak data structures in
scheme.  But, I have to admit that the only situation where guile's weak
vectors were insufficient (or better: somewhat inappropriate) for me was
when I worked on the weak observers.

Best regards,
Dirk Herrmann




reply via email to

[Prev in Thread] Current Thread [Next in Thread]