caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Weak hash table for attaching extra data to an object
@ 2007-08-14 10:15 Richard Jones
  2007-08-14 11:08 ` [Caml-list] " Thomas Fischbacher
  2007-08-14 16:22 ` [Caml-list] Weak hash table for attaching extra data to an object Richard Jones
  0 siblings, 2 replies; 15+ messages in thread
From: Richard Jones @ 2007-08-14 10:15 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2007-08-16 16:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-14 10:15 Weak hash table for attaching extra data to an object 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
2007-08-14 23:35   ` Fernando Alegre
2007-08-15  7:59     ` Richard Jones

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).