From: Tiphaine Turpin <tiphaine.turpin@free.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] application scope for hashtable on weak pointers
Date: Sat, 03 Mar 2012 20:50:51 +0100 [thread overview]
Message-ID: <4F52761B.6010509@free.fr> (raw)
In-Reply-To: <4F527560.6010409@free.fr>
Le 03/03/2012 19:21, Philippe Strauss a écrit :
> I'm puzzled by this superb sentence in the refman:
>
> "A weak hash table is a hashed set of values.
> Each value may magically disappear from the
> set when it is not used by the rest of the program any more."
>
> I have a use case for an hashtable of values who'll needs to get aged and removed after a while,
> what can I reuse of the standard lib, under which conditions are the values collected by the GC ?
A value in a weak hash-table may be collected provided :
- it is not reachable (from the roots of the reachable heap, i.e., the
stack, C-registered pointers, etc.) except through paths having a
weak-pointer (which is the case for the weak hash-table)
- the triggering conditions for the GC are met.
A typical use-case is hash-consing (physical sharing of
structuraly-equal data, for memory-efficiency).
> my use case would be to first age out when a threshold of number of bindings is reached, also, after some wall time, flush oldest entries (LRU).
Maybe you can have a "LRU-sorted" (normal) array of not-too-old data and
a weak array (or hash-table) of aged data that the GC may collect, if no
one else points to it, but which you can still use until the next collection
Tiphaine
next parent reply other threads:[~2012-03-03 18:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4F527560.6010409@free.fr>
2012-03-03 19:50 ` Tiphaine Turpin [this message]
2012-03-03 18:21 Philippe Strauss
2012-03-04 18:02 ` Daniel Bünzli
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=4F52761B.6010509@free.fr \
--to=tiphaine.turpin@free.fr \
--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