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=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 174DBBBCA for ; Mon, 31 Mar 2008 13:27:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkBABZo8EdQW+UCiGdsb2JhbACRRgEBAQ8mlmw X-IronPort-AV: E=Sophos;i="4.25,582,1199660400"; d="scan'208";a="8998539" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 31 Mar 2008 13:27:44 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2VBRW13023977 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 31 Mar 2008 13:27:44 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjkBABZo8EdQW+UCiGdsb2JhbACRRgEBAQ8mlmw X-IronPort-AV: E=Sophos;i="4.25,582,1199660400"; d="scan'208";a="8998527" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail2-smtp-roc.national.inria.fr with ESMTP; 31 Mar 2008 13:27:36 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JgIAl-0003Q7-Id for caml-list@inria.fr; Mon, 31 Mar 2008 11:27:31 +0000 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 31 Mar 2008 11:27:31 +0000 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 31 Mar 2008 11:27:31 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: bigarray & int24 Date: Mon, 31 Mar 2008 11:27:16 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/0.9.8.1pl2 (Debian) Sender: news X-Miltered: at discorde with ID 47F0CAA4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; le-gall:01 bigarray:01 byte:01 integers:01 bigarray:01 nativeint:01 ocaml:01 ocaml:01 wrote:01 abstract:01 int:01 int:01 data:02 data:02 supported:02 Hello, On 31-03-2008, Christoph Bauer wrote: > Hi, > > my program should read unaligned 3 byte integers. (A real world > example for such a format would be an RGB image). What is > the best approach? > > - extend bigarray for the int24 format and send the patch to INRIA > - write a C-function, which converts the data to an int32-array > - read an 1-byte-bigarray and construct an int-bigarray > - ??? > > It should be a bigarray solution, because my program reads other > (supported) > formats as well. > > Speed matters, because there are a lot of data. > If speed matters, you could use an alternate approach that can give you a very efficient way of processing: * keep an int32/int64 bigarray (use native int format -- the one which is the more efficient) * use a number of row that allow you to fit a x 24 bit data in b x (32/64) bit data (least common multiplicator / 32 or 64) * create a layer that allow you to process your packed data This is a way to minimize the number of unaligned access, being fully compatible with your raw format. You will still have an issue with conversion to Nativeint when extracting data. So i recommend you to write your abstract layer in C (gaining full speed for extraction of packed-aligned data and conversion) and to return OCaml int (which is possible since your data are only 24 bits long). This is not very OCaml friendly -- but allow you to get the best in term of speed. Regards, Sylvain Le Gall