Version française
Home     About     Download     Resources     Contact us    
Browse thread
Questions on replacing finalizers and memory footprints
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: forum@x9c.fr <forum@x...>
Subject: Re: [Caml-list] Questions on replacing finalizers and memory footprints

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