Version française
Home     About     Download     Resources     Contact us    
Browse thread
Weak hash table for attaching extra data to an object
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object
On 8/14/07, Richard Jones <rich@annexia.org> wrote:
> Attached is my attempt to make a WeakMetadata module (a weak hash
> table where only the key is weak and the value is used to store
> metadata about the key).  It is derived from Remi Vanicat's Hweak
> module, which is itself derived from the weak set in stdlib.
>
> Unfortunately it relies on the following being safe.  I have no idea
> if this is safe or not.
>
>   Array.create 0 (Obj.magic ())
You seem to be asking for trouble here. From what I read in your code
this *should* work. It is however highly dependent on the garbage
collector implementation: the first bit contains tells it whether this
is a block or not.

I would recommend using options instead (and again you might just use
my library but that shameless self promotion). Using options will have
a performance impact. You can can see your solution as a clever (yet
brittle) optimization hack.
However if you are hellbent on performances you might also consider
having direct access to your keys (fore quality) and collisions stored
in another table.

Regards,
Till
> Also it doesn't clean up the extra data (metadata) very aggressively.
> It basically waits for it to get overwritten when further bindings are
> added to a bucket.  So if the metadata is very large it would be worth
> adding some sort of "compact" method.
>
> Rich.
>
> --
> Richard Jones
> Red Hat
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>
>


-- 
http://till-varoquaux.blogspot.com/