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 p06EvIov011405 for ; Thu, 6 Jan 2011 15:57:18 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmkBAJNmJU1CbwQZkWdsb2JhbACWCo4PFQEBAQEHDQoHEQQgvT0FhUyEa4Yi X-IronPort-AV: E=Sophos;i="4.60,283,1291590000"; d="scan'208";a="84549807" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 06 Jan 2011 15:57:13 +0100 Received: from compute3.internal (compute3.nyi.mail.srv.osa [10.202.2.43]) by gateway1.messagingengine.com (Postfix) with ESMTP id 712B120D27 for ; Thu, 6 Jan 2011 09:57:12 -0500 (EST) Received: from frontend2.messagingengine.com ([10.202.2.161]) by compute3.internal (MEProxy); Thu, 06 Jan 2011 09:57:12 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=date:from:to:subject:message-id:references:mime-version:content-type:in-reply-to; s=smtpout; bh=DKtBveGYmR2jw7DhIiOFLd/r80M=; b=scEmvo4HEaPXetpuf2+RlASknnLnFQHM7f5YUa5ButXDIk8B6iBi6e7HOb97NvtvvbYcGCndBQ7dQ/jgeiQTjXcwEBbPC+V/P31bqJWQM/3i0WVKnh43Pmw4febKldPlvjVKeBfh6PVmFV44jFXQZyPLjBhMBg5BAtqGLMxrT34= X-Sasl-enc: qwvgqy5NzbV/Ne/a6IR3OPb/mIksr0pAFX6HnvcCfKY+ 1294325832 Received: from localhost (user-12hdvta.cable.mindspring.com [69.22.255.170]) by mail.messagingengine.com (Postfix) with ESMTPSA id 12F59444AE1 for ; Thu, 6 Jan 2011 09:57:12 -0500 (EST) Date: Thu, 6 Jan 2011 09:59:24 -0500 From: Jim Pryor To: caml-list@inria.fr Message-ID: <20110106145924.GE12229@vaio.hsd1.pa.comcast.net> Mail-Followup-To: caml-list@inria.fr References: <20110106130539.GB12229@vaio.hsd1.pa.comcast.net> <20110106144406.GD12229@vaio.hsd1.pa.comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110106144406.GD12229@vaio.hsd1.pa.comcast.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] memory leak in toplevel? or, how to implement sizeof On Thu, Jan 06, 2011 at 09:44:06AM -0500, Jim Pryor wrote: > Thanks David. So does this look like a reasonable implementation of > sizeof: > > # let sizeof maker arg = > let first = Gc.((stat()).minor_words) in > let res = maker arg in > let second = Gc.((stat()).minor_words) in > int_of_float (second -. first) - 23 ( *overhead *), res;; > > # sizeof (fun x -> [x]) 1;; > - : int * int list = (3, [1]) > > # sizeof (fun x -> Some x) 1;; > - : int * int option = (2, Some 1) > > It does give the right answers. ([1] is a block containing two non-blocks; Some 1 is a block containing one non-block.) Actually I think the overhead should be 22. Making it 22 gives these sensible results: # sizeof (fun x -> x) 10;; - : int * int = (1, 10) That is, one word for the int. # sizeof (fun x -> (x,()) ) 10;; - : int * (int * unit) = (4, (10, ())) One word for the block pointer, one word for the block header, one word for each of the two elements of the block. # sizeof (fun x -> (x,(x,())) ) 10;; - : int * (int * (int * unit)) = (7, (10, (10, ()))) Four words as above, one of them pointing to a new block, which contains a header and two elements. -- Jim Pryor profjim@jimpryor.net