On 11/21/06, Olivier Andrieu <oandrieu@nerim.net> wrote:
> I am writing a program that encodes data in 32 bit ints. Ideally I would
> like to have 32 bit unsigned ints, but OCaml only has 31 bit signed ints.
It also has 32 bits signed ints (and 64 bits).
Yes but the type int32 is not as efficient as int and I have huge data file.
From the reference manual: "
Performance notice: values of type int32
occupy more memory
space than values of type int
, and arithmetic operations on
int32
are generally slower than those on int
. Use int32
only when the application requires exact 32-bit arithmetic."
> I have a large binary file with the data that I will mmap with the
> Bigarray.Array1.map_file function.
>
> When I test the following code I am puzzled by the fact that Ocaml doesn't
> give me back the int in the same format as I wrote it.
>
> Why doesn't OCaml read back data in the same format?
because `output_binary_int' uses a big-endian encoding (cf. the reference
manual) whereas Bigarray.map_file uses the native endianess (probably
little-endian in your case).
Don't use different methods to write your data and read it back !
Is there some library for writing binary int (not int32) that writes the data in little endian (I think map_file reads it back in little endian on my processor) ?