Computes the total size (in words, including the headers) of all heap blocks accessible from the argument. Statically allocated blocks are excluded. @Since 4.04
Obj.reachable_words takes input type Obj.t, so for example:
spacetime should be an other solution - it provides a useful graph to have a global and a more specific view of your allocation. However, you probably need a powerful computer to compile switch.
Isn’t there a quick and dirty way?
I’m ok if the measurement is not super precise, I just want to have an order of idea.
I was thinking something using Gc stats should be possible.
At first sight, threads and signals would mess with the minor heap in hard to predict ways.
Then, it would work only if Toto.create does not allocate anything at all but the data that will eventually be reachable from the result (which seams unlikely), and that it does only allocate on ocaml heap, and that it does not trigger the Gc for any other reason.
Also, it would help to enlarge the default minor heap size (OCAMLRUNPARAM=s=100M ?) and to call Gc.minor first.
If all the above conditions are met then I would also expect this to work, including in native code compiled programs.
But to met all those conditions is hard. It took me a while to find a suitable exemple in the program I’m currently working on, and I eventually settled on a mere Hashtbl.create:
let some_empty_hash =
Gc.minor ();
let before = Gc.minor_words () in
let x = ref (Hashtbl.create 11) in
let after = Gc.minor_words () in
Printf.printf "Size of Hashtbl(11) = %g - %g = %g\n%!" after before (after -. before) ;
x