检查 ocaml 中的记录大小?
有没有办法检查 Ocaml 中记录的大小?类似于 C/C++ 的 sizeof
吗?
Is there any way to check the size of a record in Ocaml? Something like sizeof
of C/C++?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的:
但是对于记录类型,大小仅取决于类型声明,因此您可以从中推断出来。
实际占用内存的大小是
Obj.size
返回的数字加一(以字为单位)。字是 32 位还是 64 位,具体取决于您使用的 OCaml 版本。附加词用于簿记。Yes:
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.除了 Obj 模块之外,还有 Dmitry Grebeniuk 提供的 Objsize 库( http://forge.ocamlcore.org/项目/objsize/ )。它允许您获取有关值及其大小的更详细信息。
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.