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=0.0 required=5.0 tests=AWL 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 C2980BC69 for ; Thu, 6 Dec 2007 17:59:51 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApkZAOe4V0fUnw6GYmdsb2JhbACCOI0VFQQGEBIH X-IronPort-AV: E=Sophos;i="4.23,261,1194217200"; d="scan'208";a="4968765" Received: from pih-relay08.plus.net ([212.159.14.134]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Dec 2007 17:59:51 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay08.plus.net with esmtp (Exim) id 1J0K4k-0004UH-Ix for caml-list@yquem.inria.fr; Thu, 06 Dec 2007 16:59:50 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Questions on replacing finalizers and memory footprints Date: Thu, 6 Dec 2007 16:50:32 +0000 User-Agent: KMail/1.9.5 References: <4757D904.2090502@functionality.de> <20071206142609.GA15768@furbychan.cocan.org> <47580DE4.40503@functionality.de> In-Reply-To: <47580DE4.40503@functionality.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200712061650.32678.jon@ffconsultancy.com> X-Spam: no; 0.00; finalizers:01 footprints:01 ocaml:01 marshalling:01 hash:01 frog:98 wrote:01 wrote:01 ints:01 caml-list:01 marshal:01 marshal:01 int:01 int:01 data:02 On Thursday 06 December 2007 14:57, Thomas Fischbacher wrote: > Richard Jones wrote: > > If you want to do this in pure OCaml, probably your best bet would be > > to just Marshal the structure and count how big it is. It'll be slow > > of course. > > Actually, the situation that brought up this question is that I have a > complicated internal data structure which will free 300 MB of RAM if I > delete it, while serializing it produces a file of 94 MB only... > So, I would like to have more clarity what is going on here, and which > part of this data structure eats how much space. I had never though of measuring the size of a marshalled data structure. Turns out its representation of ints can be more concise than the code representation though: # String.length (Marshal.to_string (Array.make 1000000 0) []);; - : int = 1000025 # String.length (Marshal.to_string (Array.make 1000000 123456789) []);; - : int = 5000025 # String.length (Marshal.to_string (Array.make 1000000 max_int) []);; - : int = 9000025 which is probably what you're observing. Marshalling also handles sharing but that seems to refer to DAGs in memory rather than hash consing: # String.length (Marshal.to_string (Array.make 1000000 0., Array.make 1000000 0.) []);; - : int = 16000031 -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e