Browse thread
Questions on replacing finalizers and memory footprints
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Questions on replacing finalizers and memory footprints |
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