开发者

Checking record size in ocaml?

开发者 https://www.devze.com 2023-01-22 04:35 出处:网络
Is there any way to check the size of a record in Ocaml? Something like size开发者_StackOverflowof of C/C++?Yes:

Is there any way to check the size of a record in Ocaml? Something like size开发者_StackOverflowof of C/C++?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消