ocamlmanual

Missing clarification in the OCaml manual about unboxed/boxed


The OCaml manual states:

As another optimization, unboxable record types are represented specially; unboxable record types are the immutable record types that have only one field.

(https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#ss:c-tuples-and-records)

But which type can that "one field" have? Only native, or any record type?


Solution

  • Any type: OCaml memory representation is uniform.

    More precisely, in term of memory representation, OCaml values are either integer or pointers to a block. And a block consists in a header followed by a number of values.

    Unboxing replaces the unboxed memory representation of a pointer to a block which contains only one OCaml value by this value.