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.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id C176CBBAF for ; Thu, 24 Jul 2008 17:45:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQCANRAiEiYToBnc2dsb2JhbACSVAEMAgsHEQWeQw X-IronPort-AV: E=Sophos;i="4.31,247,1215381600"; d="scan'208";a="15460366" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 24 Jul 2008 17:45:04 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m6OFj49E032489 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 24 Jul 2008 17:45:04 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtQCANRAiEiYToBnc2dsb2JhbACSVAEMAgsHEQWeQw X-IronPort-AV: E=Sophos;i="4.31,247,1215381600"; d="scan'208";a="15460364" Received: from mailgate2.iss.soton.ac.uk ([152.78.128.103]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Jul 2008 17:45:04 +0200 Received: from [152.78.96.56] (alpha.kk.soton.ac.uk [152.78.96.56]) (authenticated bits=0) by mailgate2.iss.soton.ac.uk (8.13.8/8.13.4) with ESMTP id m6OFiwKO010240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Jul 2008 16:44:58 +0100 Message-ID: <4888A37A.5090407@soton.ac.uk> Date: Thu, 24 Jul 2008 16:44:58 +0100 From: "Dr. Thomas Fischbacher" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060607 Debian/1.7.12-1.2 X-Accept-Language: en MIME-Version: 1.0 To: Alain Frisch Cc: dmitry grebeniuk , "caml-list@inria.fr" Subject: Re: [Caml-list] Memory statistics tool References: <48870DD8.4050906@soton.ac.uk> <1497034692.20080723154431@moldavcable.com> <48872D6E.20209@soton.ac.uk> <48872F38.30609@frisch.fr> <48887A16.1070906@soton.ac.uk> <48889C59.8080806@frisch.fr> In-Reply-To: <48889C59.8080806@frisch.fr> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-3.0 (mailgate2.iss.soton.ac.uk [152.78.128.103]); Thu, 24 Jul 2008 16:44:58 +0100 (BST) X-ISS-MailScanner-Information: Please contact Serviceline@soton.ac.uk for more information X-ISS-MailScanner: Found to be clean X-ISS-MailScanner-SpamCheck: X-Miltered: at discorde with ID 4888A380.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; frisch:01 hash:01 hash:01 hashtbl:01 struct:01 hashtbl:01 ocaml:01 ocaml:01 toplevel:01 equality:01 equality:01 polymorphic:01 polymorphic:01 wrote:01 dmitry:01 Alain Frisch wrote: >>>As long as the data structure supports the polymorphic hash function, it >>>should work to simply use a regular hash table with the polymorphic hash >>>function and physical equality, as in: >>> >>>module S = Hashtbl.Make(struct >>> type t = Obj.t >>> let hash = Hashtbl.hash >>> let equal = (==) >>>end);; >> >>Why? (I.e. I'm not convinced yet.) > > > The two functions (hash and equal) are invariant w.r.t. changes of > physical memory location of their arguments. The OCaml manual gives no guarantee that Hashtbl.hash does not cons, so I cannot assume this. Now, without that guarantee, there is a nasty race condition in which the determination of the hash bucket causes objects to move in memory. But still, we are safe, as we are just testing for equality, and the hash bucket does not depend on the memory address, but on the substructure of the hashed entity. So, ok, you convinced me. Anyway, it works now -- thanks to Dmitry's code, I can now do things like...: tf@alpha:~/ocaml$ nsim_i In [1]: ocaml.memory_footprint(ocaml.make_element("E",[3],3,1)) Out[1]: (154.0, 49.0, 5.0) In [2]: ...and use the interactive Python toplevel of our micromagnetic simulator "nmag" to find out how much memory is used by the OCaml data structures under the hood. Excellent. Thanks, Dmitry! -- best regards, Thomas Fischbacher t.fischbacher@soton.ac.uk