From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p07CPlBm024112 for ; Fri, 7 Jan 2011 13:25:47 +0100 X-IronPort-AV: E=Sophos;i="4.60,289,1291590000"; d="scan'208";a="94761162" Received: from 250-120.msr-inria.inria.fr (HELO [10.0.1.3]) ([193.55.250.120]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/AES128-SHA; 07 Jan 2011 13:25:42 +0100 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1082) From: Damien Doligez In-Reply-To: <20110106145924.GE12229@vaio.hsd1.pa.comcast.net> Date: Fri, 7 Jan 2011 13:25:42 +0100 Content-Transfer-Encoding: 7bit Message-Id: <7577E373-EB25-4A7E-90C1-30491F27B4F9@inria.fr> References: <20110106130539.GB12229@vaio.hsd1.pa.comcast.net> <20110106144406.GD12229@vaio.hsd1.pa.comcast.net> <20110106145924.GE12229@vaio.hsd1.pa.comcast.net> To: caml users X-Mailer: Apple Mail (2.1082) Subject: Re: [Caml-list] memory leak in toplevel? or, how to implement sizeof On 2011-01-06, at 15:59, Jim Pryor wrote: > Actually I think the overhead should be 22. Making it 22 gives these > sensible results: The overhead is exactly the heap space used by the value returned by Gc.stat. In your case it is 23 words, not 22. > # sizeof (fun x -> x) 10;; > - : int * int = (1, 10) > > That is, one word for the int. The int is not allocated in the heap, so the result should be 0. It is best to let ocaml compute the overhead, because it will be different on 32- and 64-bit machines: let overhead = let first = Gc.((stat()).minor_words) in let second = Gc.((stat()).minor_words) in int_of_float (second -. first) ;; -- Damien