From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=SPF_NEUTRAL,SUBJECT_EXCESS_QP autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 19BC9BC69 for ; Sat, 8 Dec 2007 11:06:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAP/7WUeBaB4ik2dsb2JhbACPXQEBAQEHBAYJIIEU X-IronPort-AV: E=Sophos;i="4.23,270,1194217200"; d="scan'208";a="5017414" Received: from mx1.polytechnique.org ([129.104.30.34]) by mail2-smtp-roc.national.inria.fr with ESMTP; 08 Dec 2007 11:06:35 +0100 Received: from alexandre.pilkiewicz?polytechnique.org (AFontenayssB-152-1-55-53.w82-121.abo.wanadoo.fr [82.121.239.53]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ssl.polytechnique.org (Postfix) with ESMTP id A5FF633168 for ; Sat, 8 Dec 2007 11:06:34 +0100 (CET) From: Alexandre Pilkiewicz To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Questions on replacing finalizers and =?iso-8859-1?q?memory=09footprints?= Date: Sat, 8 Dec 2007 10:57:54 +0100 User-Agent: KMail/1.9.7 References: <4757D904.2090502@functionality.de> <4759A501.7070809@lri.fr> <75D66E7E-2C71-40E3-8F94-129821A06FFA@x9c.fr> In-Reply-To: <75D66E7E-2C71-40E3-8F94-129821A06FFA@x9c.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200712081057.54605.alexandre.pilkiewicz@polytechnique.org> X-AV-Checked: ClamAV using ClamSMTP at djali.polytechnique.org (Sat Dec 8 11:06:34 2007 +0100 (CET)) X-Org-Mail: alexandre.pilkiewicz.2004@polytechnique.org X-Spam: no; 0.00; finalizers:01 footprints:01 filliatre:01 hashtable:01 hash:01 hash:01 hashtbl:01 node:01 memq:01 node:01 garbage:01 caml-list:01 termination:01 int:01 append:02 Le Friday 07 December 2007 22:01:23 forum@x9c.fr, vous avez =E9crit=A0: > Le 7 d=E9c. 07 =E0 20:54, Jean-Christophe Filli=E2tre a =E9crit : > My mistake, I did not take into account the fact that if a block is > moved by the > garbage collector, its reference is updated in the hashtable *too*. > Hence the termination guarantee. I think the problem is with the hash function : let hash o =3D Hashtbl.hash (magic o : int) If you put an object in the hash table, it is stored under a key that depen= ds=20 on it's address a1. Once it's moved by the GC to the address a2, its=20 reference is changed to a2, but not its key which is still the hash of a1. = So=20 when you check after that if your object is allready in the hash table, you= =20 look under the key hash(a2) if it's allready there, but it's not ! And if y= ou=20 are very unlucky (and have very few memory), it might append several time. One solution could be to store the objects in a normal list and to look at = the=20 entire list every time. It would be *much* slower on huge structures, but=20 probably more "correct" (so if used only for debug purpose, why not..) let node_list =3D ref [] let in_list o =3D List.memq o !node_list let add_in_list o =3D node_list :=3D o::!node_list let reset_list () =3D node_list :=3D [] =2D-=20 Alexandre Pilkiewicz