caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Threads performance issue.
Date: Tue, 17 Feb 2009 11:33:03 +0000	[thread overview]
Message-ID: <200902171133.03903.jon@ffconsultancy.com> (raw)
In-Reply-To: <2184b2340902170250g75d4482bt1d49e0e295c2e6d7@mail.gmail.com>

On Tuesday 17 February 2009 10:50:44 Rémi 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, which 
used file mapping as an easy way to load texture maps. First, you open the 
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 = 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 
string:

       String.init (Array1.dim source) (fun i -> Char.chr source.{i}))

Finally, you close the file:

    Unix.close

Note that I have used try_finally and String.init functions from my own stdlib 
but their purpose and use should be obvious.

You probably just want to replace read_char with a function that increments a 
counter and reads from the array, with the whole parser inside the 
try_finally.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


  parent reply	other threads:[~2009-02-17 11:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-16 15:15 Rémi Dewitte
2009-02-16 15:28 ` [Caml-list] " Michał Maciejewski
2009-02-16 15:32   ` Rémi Dewitte
2009-02-16 15:42     ` David Allsopp
2009-02-16 16:07       ` Rémi Dewitte
2009-02-16 16:32 ` Sylvain Le Gall
2009-02-17 13:52   ` [Caml-list] " Frédéric Gava
2009-02-16 16:47 ` [Caml-list] " Yaron Minsky
2009-02-16 17:37   ` Rémi Dewitte
2009-02-17  7:40     ` Rémi Dewitte
2009-02-17  8:59       ` Mark Shinwell
2009-02-17  9:09         ` Rémi Dewitte
2009-02-17  9:53         ` Jon Harrop
2009-02-17 10:07       ` Sylvain Le Gall
2009-02-17 10:26         ` [Caml-list] " Mark Shinwell
2009-02-17 10:50           ` Rémi Dewitte
2009-02-17 10:56             ` Mark Shinwell
2009-02-17 11:33             ` Jon Harrop [this message]
2009-02-17 12:20         ` Yaron Minsky
2009-02-17 12:26           ` Rémi Dewitte
2009-02-17 17:14           ` Sylvain Le Gall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200902171133.03903.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).