[Ecls-list] Finalizer, weak pointer, weak hashes etc.

Juan Jose Garcia-Ripoll jjgarcia at users.sourceforge.net
Wed Apr 30 14:17:59 UTC 2008

On Tue, Apr 29, 2008 at 6:40 PM, Marco Gidde <marco.gidde at tiscali.de> wrote:
>  The meaning of alloc_atomic() and GC_general_register_disappearing_link
>  was already clear - I used them in my weak pointer patch. It seems there
>  is some disagreement between us concerning who should do the "dirty"
>  work of cleaning up the references: my idea was that if there is no need
>  for finalizers to implement the hash table, the clean up could just as
>  well be done by the GC (e.g. GC_general_register..). As I understand it,
>  GC_general_register.. is nothing more than a specialized finalizer that
>  nullifies a pointer if some other object is garbage collected.

You are right.

>  On the other side you would like to control the cleanup from within ECL,
>  which is also OK, but not what I would do. But in the end you are the
>  maintainer and I guess you have some further ideas how to optimize the
>  GC for ECL's purposes. :-)

Well, what I have in mind is a setup in which I do not need to teach
the old garbage collector to implement disappearing links.

>  One technical problem I see is using the hash table to implement the
>  association for the weak pointers. It seems that you have to support
>  three different kinds of hash keys then: regular pointers, weak pointers
>  for the weak hashes and some kind of hidden pointers for the
>  implementation of the weak pointers. Or would you use some
>  simplified/special purpose hash implementation only for the latter?

Indeed one only needs one kind of hash tables. The weak version of a
hash table stores as keys, instead of the object, their weak pointers.
The difference in these tables is that the comparison (EQ, EQL, EQUAL,
etc) has to look inside the weak pointer. To keep track of the created
weak pointers you can create a weak hash table that associates objects
to their weak pointers :-) This table will keep the weak pointers
alive and you do not need an additional data structure. I think this
is cute and elegant.

>  My impression was that it might be even possible to simply integrate
>  t_weakpointer in the _hash_eq.. functions. However it's done, additional
>  to that ecl_search_hash (and cl_maphash/si_hash_table_iterate) would
>  probably be responsible for removing hash entries with a garbage
>  collected value.

As I said before, not only the hash key is important, but also the
comparison. When comparing for EQ in an weak hash table you have to
take the weak pointer containing the object and extract what is

>  Seems we're getting closer to an implementation ;-)



Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)

More information about the ecl-devel mailing list