Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
reading/writing binary data
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-11-21 (13:29)
From: Dário_Abdulrehman <drehman31@g...>
Subject: Re: [Caml-list] reading/writing binary data
On 11/21/06, Olivier Andrieu <> 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) ?