From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q23IpJ0q032138 for ; Sat, 3 Mar 2012 19:51:19 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvgCAKlnUk/UGyoBkWdsb2JhbABDgxauO4J8IgEBAQEJCwsHFAMkgX0BAQQBMgFFBgsLIRYPCQMCAQIBRRMIAQGHfgm3FY07gyIElT6FYY0V X-IronPort-AV: E=Sophos;i="4.73,526,1325458800"; d="scan'208";a="134183711" Received: from smtp1-g21.free.fr ([212.27.42.1]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Mar 2012 19:51:13 +0100 Received: from [192.168.0.3] (bur91-2-82-231-161-160.fbx.proxad.net [82.231.161.160]) (Authenticated sender: tiphaine.turpin) by smtp1-g21.free.fr (Postfix) with ESMTPA id 432E594018A for ; Sat, 3 Mar 2012 19:51:06 +0100 (CET) Message-ID: <4F52761B.6010509@free.fr> Date: Sat, 03 Mar 2012 20:50:51 +0100 From: Tiphaine Turpin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111221 Thunderbird/8.0 MIME-Version: 1.0 To: caml-list@inria.fr References: <4F527560.6010409@free.fr> In-Reply-To: <4F527560.6010409@free.fr> X-Forwarded-Message-Id: <4F527560.6010409@free.fr> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] application scope for hashtable on weak pointers 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