Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "forum@x9c.fr" <forum@x9c.fr>
To: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Questions on replacing finalizers and memory footprints
Date: Thu, 6 Dec 2007 22:33:49 +0100	[thread overview]
Message-ID: <5208F98A-4688-46EB-B051-F896B18D0ED9@x9c.fr> (raw)
In-Reply-To: <200712061650.32678.jon@ffconsultancy.com>


Le 6 déc. 07 à 17:50, Jon Harrop a écrit :

> 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:

(...)

Yes, the marshalled format although not compressed is quite optimized.
For example, if I am not wrong, an "int" value in 0..63 will be coded  
on a
single byte. Such a value may take up to 8 times more space in memory
if you are using a 64-bit architecture. The same is of course also  
true for
all data types that are represented at runtime by values in 0..63
(e.g. variant with no embedded data).
The same kind of encoding is used for "small" blocks, whose headers are
stored more compactly in a marshalled stream than in memory.

As a consequence, it is not very surprising that you observe a 3:1 ratio
between in-memory and marshalled representations.


Xavier Clerc

  reply	other threads:[~2007-12-06 21:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-06 11:12 Thomas Fischbacher
2007-12-06 12:51 ` [Caml-list] " dmitry grebeniuk
2007-12-06 14:26 ` Richard Jones
2007-12-06 14:57   ` Thomas Fischbacher
2007-12-06 16:50     ` Jon Harrop
2007-12-06 21:33       ` forum [this message]
2007-12-07  8:52 ` Xavier Leroy
2007-12-07 10:44   ` Jean-Christophe Filliâtre
2007-12-07 10:35     ` Jon Harrop
2007-12-07 11:18     ` forum
2007-12-07 19:54       ` Jean-Christophe Filliâtre
2007-12-07 21:01         ` forum
2007-12-08  9:57           ` Alexandre Pilkiewicz
2007-12-08 14:20             ` Benjamin Canou
2007-12-07 20:31     ` Christophe Raffalli
2008-01-23 12:08     ` Hendrik Tews
2007-12-07 11:31   ` Berke Durak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5208F98A-4688-46EB-B051-F896B18D0ED9@x9c.fr \
    --to=forum@x9c.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox