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

Re: GC and tables



    Can you enlighten me about what OBJECT-HASH and OBJECT-UNHASH do,
    and what populations are?  This is an old, vexing problem in all
    the systems I know and love.
    
OBJECT-HASH and OBJECT-UNHASH implement "weak pointers", a concept
which I believe first appeared in MacLisp.  (The T sources acknowledge
Gerry Sussman and Carl Hewitt.)  The idea is to have a pointer to an
object which is not strong enough to prevent it from being GCed, and
the implementation is essentially to convert a pointer into a fixnum.

Thus, if (OBJECT-HASH foo) => k (an integer associated with the object
foo), then (OBJECT-UNHASH k) => foo IF foo has not been GCed, and "false"
otherwise.  Many print methods use OBJECT-HASH.

Populations function as "weak sets", i.e. as sets (lists) which are
not strong enough to prevent their objects from being GCed.  They could
easily be implemented by a list of weak pointers.  Operations on 
populations include MAKE, ADD-TO, REMOVE-FROM, WALK (-POPULATION), and 
POPULATION->LIST.  They are often used to keep track of all of a certain
type of object (e.g. all populations(!), all pools).  In addition, they
might be used to allow the reuse of big structures rather than consing
them in the heap.

Note that neither of these really solves my problem -- that of a 
"weak table".  I want the keys of the table to be weak pointers, but 
the entries have to be stronger than weak pointers -- I don't want 
the entries to be GCed unless the keys have been.  The best implementation
we've come up with here would be some sort of post-GC hook to remove\n from the table those (key,entry) pairs for which the key element has
been GCed.  This would GC the entries after the SECOND GC.  I suppose
this is better than nothing...

                                --- Jonathan
-------