caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: caml-list@inria.fr
Subject: Weak hash table for attaching extra data to an object
Date: Tue, 14 Aug 2007 11:15:35 +0100	[thread overview]
Message-ID: <20070814101535.GA14485@furbychan.cocan.org> (raw)

Problem:

I have a module which I can't edit[1].  This module, let's call it
Document, stores a representation of an XML tree in internal node
objects:

  type intnode

What I want to do is -- completely outside Document -- attach my own
extra information to these nodes.  The key point is that if the
garbage collector collects an intnode, then I want my extra
information to be garbage collected too.

My proposed solution would use a weak hash table similar to / derived
from this one: http://remi.vanicat.free.fr/ocaml/hweak/.  I would
store in this hash table mappings from (weak) intnode pointers to my
extra data structure.

Remi's Hweak module isn't quite what I need because the data is also
weak.  Since nothing except the hash table itself is tracking my extra
data, the GC can potentially drop all of the bindings, and that's not
much help.

I tried to modify Hweak so that the data is not weak, but that proved
to be quite hard.

I wonder if anyone has done this, or can suggest a better way to solve
this problem?  The issue of attaching extra data to some existing
object would seem to be a fairly common one ...

Rich.

[1] By "can't edit" I really mean "don't want to modify".  I want
Document to be general purpose.  Also, unlike PXP, I want multiple
callers to be able to individually attach data to nodes.

-- 
Richard Jones
Red Hat


             reply	other threads:[~2007-08-14 10:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-14 10:15 Richard Jones [this message]
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
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=20070814101535.GA14485@furbychan.cocan.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    /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).