From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 96A66BC0B for ; Tue, 21 Nov 2006 14:29:25 +0100 (CET) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.237]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id kALDTOYh009986 for ; Tue, 21 Nov 2006 14:29:25 +0100 Received: by wx-out-0506.google.com with SMTP id i31so2005744wxd for ; Tue, 21 Nov 2006 05:29:24 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=RRi1y2wB+cHcCm1F47aVnGMypKZsXDHkpqtr9jVAuCsRp2oH8ay/8JlQFbKfEbIplY1T+ERHY5p8UBkTLVQZ+xlnS0mKelOw1ptvRA7G0M50RuX4xgmkiwYb6TNfKFwR/iYChqBh7XN3UrO0Y6L7Vi9SuR3OgQlV9KeeshlxovM= Received: by 10.90.105.19 with SMTP id d19mr5214999agc.1164115764064; Tue, 21 Nov 2006 05:29:24 -0800 (PST) Received: by 10.35.113.4 with HTTP; Tue, 21 Nov 2006 05:29:23 -0800 (PST) Message-ID: <6aeedf580611210529k57456af5y5e321e0670c26fe0@mail.gmail.com> Date: Tue, 21 Nov 2006 13:29:23 +0000 From: "=?ISO-8859-1?Q?D=E1rio_Abdulrehman?=" To: "Olivier Andrieu" Subject: Re: [Caml-list] reading/writing binary data Cc: caml-list@inria.fr In-Reply-To: <32511.213.30.139.86.1164114914.squirrel@webmail.nerim.net> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_17408_21203118.1164115763984" References: <6aeedf580611210334p41d2ba00jcceb00da3af0e3d2@mail.gmail.com> <32511.213.30.139.86.1164114914.squirrel@webmail.nerim.net> X-j-chkmail-Score: MSGID : 4562FF34.000 on concorde : j-chkmail score : X : 0/20 1 X-Miltered: at concorde with ID 4562FF34.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 encodes:01 ocaml:01 bigarray:01 ocaml:01 int':01 big-endian:01 bigarray:01 endian:01 endian:01 andrieu:01 oandrieu:01 encodes:01 int':01 ------=_Part_17408_21203118.1164115763984 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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) ? ------=_Part_17408_21203118.1164115763984 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

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) ?

------=_Part_17408_21203118.1164115763984--