caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Till Varoquaux" <till.varoquaux@gmail.com>
To: "Richard Jones" <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Weak hash table for attaching extra data to an object
Date: Wed, 15 Aug 2007 01:24:51 +0200	[thread overview]
Message-ID: <9d3ec8300708141624j676f8384ya93db222c2ed2b7b@mail.gmail.com> (raw)
In-Reply-To: <20070814162206.GA1651@furbychan.cocan.org>

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/


  reply	other threads:[~2007-08-14 23:24 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-14 10:15 Richard Jones
2007-08-14 11:08 ` [Caml-list] " Thomas Fischbacher
2007-08-14 11:48   ` Till Varoquaux
2007-08-14 20:44   ` Jon Harrop
2007-08-14 23:09     ` Stefano Zacchiroli
2007-08-15  0:33       ` Jon Harrop
2007-08-15 12:33         ` Daniel Bünzli
2007-08-16 14:54         ` Markus Mottl
2007-08-15  1:28     ` skaller
2007-08-15 19:04     ` Richard Jones
2007-08-16 16:17       ` Some observations and measurements with using Weak Hashtable to annotate a tree (was: Re: [Caml-list] Weak hash table for attaching extra data to an object) Richard Jones
2007-08-14 16:22 ` [Caml-list] Weak hash table for attaching extra data to an object Richard Jones
2007-08-14 23:24   ` Till Varoquaux [this message]
2007-08-14 23:35   ` Fernando Alegre
2007-08-15  7:59     ` Richard Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9d3ec8300708141624j676f8384ya93db222c2ed2b7b@mail.gmail.com \
    --to=till.varoquaux@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=rich@annexia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).