Checking record size in ocaml?

Is there a way to check the recording size in Ocaml? Something like sizeof for C / C ++?

+4
source share
2 answers

Yes:

 # Obj.size (Obj.repr (1,2,3,4,5)) ;; - : int = 5 

But for a record type, the size depends only on the type declaration, so you can simply infer it from this.

The actual size occupied in memory is the number returned by Obj.size plus one in words. Words are 32 or 64 bits, depending on which version of OCaml you are using. An additional word is used for accounting.

+7
source

In addition to the Obj module, there is also the Objsize library from Dmitry Grebenyuk ( http://forge.ocamlcore.org/projects/objsize/ ). It allows you to get more detailed information about the values ​​and size.

+1
source

All Articles