[Gc] weak maps and libgc

Petter Urkedal urkedal at nbi.dk
Tue Oct 25 13:28:47 PDT 2011

On 2011-10-25, Andy Wingo wrote:
> Hi Petter,
> Thanks for the note!
> On Tue 25 Oct 2011 19:18, Petter Urkedal <urkedal at nbi.dk> writes:
> > Ivan recently accepted a patch I've been using for some time to
> > implement hash-consing efficiently.  The API is found in "gc_disclaim.h".  I
> > intended it to be general enough to implement other weak data structures, as
> > well.
> Do you have to allocate the keys in your table to be of a certain kind?
> In my case that is not possible, if I understand you correctly, as the
> objects might already have another kind of their own.

Yes, or at least you need to store a pointer from your keys to an object
of that kind, and probably back again in order to delete the entry.  You
could call GC_register_disclaim_proc on your own kind, but that may not
be feasible performance-wise if it's a generally used kind.  That is,
unless you also happen to need finalizers on a large fraction of
objects, in which case the disclaim call-back can be used to call the
finalizers, as well.

I haven't benchmarked precisely, but:  GC_register_disclaim_proc should
have a sight performance impact on object ignored by the call-back with
mark-from-all disabled, while I would expect more significant impact
with mark-from-all enabled.

More information about the Gc mailing list