检查 ocaml 中的记录大小?

发布于 2024-09-29 17:44:51 字数 62 浏览 0 评论 0原文

有没有办法检查 Ocaml 中记录的大小?类似于 C/C++ 的 sizeof 吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九厘米的零° 2024-10-06 17:44:51

是的:

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

但是对于记录类型,大小仅取决于类型声明,因此您可以从中推断出来。

实际占用内存的大小是Obj.size返回的数字加一(以字为单位)。字是 32 位还是 64 位,具体取决于您使用的 OCaml 版本。附加词用于簿记。

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.

毁梦 2024-10-06 17:44:51

除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文