为什么产品比记录使用更多内存?

dor*_*mon 4 ocaml functional-programming

根据此演示文稿(http://oud.ocaml.org/2012/slides/oud2012-paper13-slides.pdf,PDF第4页),以下两种数据结构使用不同的内存量

type t1 = { f1: float; f2:float};;
type t2 = (float * float);;
Run Code Online (Sandbox Code Playgroud)

并且t1使用的内存少于t2,有人可以向我解释为什么会这样吗?

cam*_*ter 7

http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec425的 19.3.3 说:

浮点数的数组(类型为float数组)具有特殊的,未装箱的,更有效的表示.这些数组由带有标记的块的指针表示Double_array_tag.

这是为了有效地处理大浮点数组而引入的,但这也适用于只有浮点数的记录类型.

https://realworldocaml.org/v1/en/html/memory-representation-of-values.html也是一个非常好的文档,解释了OCaml的内部价值表示.