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.4 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 0B569BB84 for ; Tue, 17 Feb 2009 12:28:11 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuMAANQtmknUnwcjlGdsb2JhbACCPZIIAQEBAQkLCAkRBLwlhBMG X-IronPort-AV: E=Sophos;i="4.38,222,1233529200"; d="scan'208";a="24197452" Received: from relay.ptn-ipout01.plus.net ([212.159.7.35]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 17 Feb 2009 12:28:10 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEANQtmknUnw6S/2dsb2JhbACCPc5rhBMG Received: from ptb-relay02.plus.net ([212.159.14.146]) by relay.ptn-ipout01.plus.net with ESMTP; 17 Feb 2009 11:28:10 +0000 Received: from [87.114.148.153] (helo=leper.local) by ptb-relay02.plus.net with esmtp (Exim) id 1LZO7V-0000Qg-Si for caml-list@yquem.inria.fr; Tue, 17 Feb 2009 11:28:10 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Threads performance issue. Date: Tue, 17 Feb 2009 11:33:03 +0000 User-Agent: KMail/1.9.9 References: <2184b2340902160715y1f935b5ehc0e6195b3f75b66b@mail.gmail.com> <20090217102659.GD29651@janestcapital.com> <2184b2340902170250g75d4482bt1d49e0e295c2e6d7@mail.gmail.com> In-Reply-To: <2184b2340902170250g75d4482bt1d49e0e295c2e6d7@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200902171133.03903.jon@ffconsultancy.com> X-Plusnet-Relay: a840a55cc8e671c040a0b07d12a691ae X-Spam: no; 0.00; bigarray:01 ocaml:01 ocaml:01 desc:01 desc:01 stdlib:01 parser:01 2009:98 increments:98 frog:98 threads:01 char:01 char:01 wrote:01 unix:01 On Tuesday 17 February 2009 10:50:44 R=C3=A9mi Dewitte wrote: > Memory mapping of the file could be done using BigArray or do I have to > write C code ? You can memory map files very easily entirely from within OCaml. This was actually covered in the OCaml Journal article about OpenGL 2, whic= h=20 used file mapping as an easy way to load texture maps. First, you open the= =20 file to create a file descriptor: try_finally (Unix.openfile file [] 777) Then you map the file to create a big array: (fun desc -> let source =3D Array1.map_file desc int8_signed c_layout false (-1) = in Then you can do something with the big array, like copy it into an ordinary= =20 string: String.init (Array1.dim source) (fun i -> Char.chr source.{i})) =46inally, you close the file: Unix.close Note that I have used try_finally and String.init functions from my own std= lib=20 but their purpose and use should be obvious. You probably just want to replace read_char with a function that increments= a=20 counter and reads from the array, with the whole parser inside the=20 try_finally. =2D-=20 Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e