What’s the advantage to reading and writing strings vs (integer) arrays? @copy also suggested this, although in my mental model they should be the same thing?
Note that since 4.08. These are also exposed by the Stdlib
. See https://github.com/ocaml/ocaml/pull/1864
It takes less memory; to represent an array of int32
values with n
elements, an int array
takes 8 * n + 8
bytes, while a string/bytes takes 4 * n + 16
bytes (or 4 * n + 12
if n is odd).
It should also be very slightly faster to use operations on unboxed int32
than regular int
, because the latter is represented with the least significant bit set to 1 and this has to be preserved.
I had forgotten about that, thanks for reminding me. Although ocplib-endian
still exposes more functions than the ones in the Stdlib
(unsafe versions, String
and Bigstring
versions).