caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] application scope for hashtable on weak pointers
       [not found] <4F527560.6010409@free.fr>
@ 2012-03-03 19:50 ` Tiphaine Turpin
  0 siblings, 0 replies; 3+ messages in thread
From: Tiphaine Turpin @ 2012-03-03 19:50 UTC (permalink / raw)
  To: caml-list


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



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

* Re: [Caml-list] application scope for hashtable on weak pointers
  2012-03-03 18:21 Philippe Strauss
@ 2012-03-04 18:02 ` Daniel Bünzli
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Bünzli @ 2012-03-04 18:02 UTC (permalink / raw)
  To: caml-list



Le samedi, 3 mars 2012 à 19:21, Philippe Strauss a écrit :

> I have a use case for an hashtable of values who'll needs to get aged and removed after a while,
That's not a good use case for weak hash tables. I explain why in this answer [1].  

Best,

Daniel

[1] http://stackoverflow.com/questions/4933729/how-are-weak-arrays-used/4935518#4935518




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

* [Caml-list] application scope for hashtable on weak pointers
@ 2012-03-03 18:21 Philippe Strauss
  2012-03-04 18:02 ` Daniel Bünzli
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Strauss @ 2012-03-03 18:21 UTC (permalink / raw)
  To: caml-list

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 ?

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


--
Philippe Strauss
http://www.strauss-acoustics.ch/







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

end of thread, other threads:[~2012-03-04 18:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4F527560.6010409@free.fr>
2012-03-03 19:50 ` [Caml-list] application scope for hashtable on weak pointers Tiphaine Turpin
2012-03-03 18:21 Philippe Strauss
2012-03-04 18:02 ` Daniel Bünzli

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