tags:

views:

40

answers:

2

Is there any way to check the size of a record in Ocaml? Something like sizeof of C/C++?

+4  A: 

Yes:

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

But for a record type, the size only depends on the type declaration, so you could just infer it from that.

The actual size occupied in memory is the number returned by Obj.size plus one in words. Words are 32 or 64 bit depending which OCaml version you are using. The additional word is used for book-keeping.

Pascal Cuoq
Just what I was looking for -- thank you!
akoprowski
A: 

Besides Obj module, there is also a Objsize library from Dmitry Grebeniuk ( http://forge.ocamlcore.org/projects/objsize/ ). It allows you to get more detailed info about values and its size.

larhat