Is there any way to check the size of a record in Ocaml? Something like sizeof
of C/C++?
views:
40answers:
2
+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
2010-10-28 13:56:55
Just what I was looking for -- thank you!
akoprowski
2010-10-28 14:21:37
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
2010-10-30 19:25:45