<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/10/99f45aa9c8324508067c19216451bca4"
  from="Gerd Stolpmann &lt;gerd@g...&gt;"
  author="Gerd Stolpmann"
  date="2009-10-28T15:38:04"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?"
  prev="2009/10/b699fc83fc25d4dfb6ba4705183804af"
  next="2009/10/02a74313db370b81dd3c6315f7190d57"
  prev-in-thread="2009/10/02a74313db370b81dd3c6315f7190d57"
  next-in-thread="2009/10/14d54df8c72e192b79db94d2c1fac31d"
  prev-thread="2009/10/a542f981ec63f1fb137050f0370eebab"
  next-thread="2009/10/63300d21e98ae03b875913a3e95f0dea"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="How to read different ints from a Bigarray?">
<msg 
  url="2009/10/bbb95d9e0194e1762c52367d01c48687"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T13:57:42"
  subject="How to read different ints from a Bigarray?">
<msg 
  url="2009/10/46931001437bcbb2e09f17cfe7df9981"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T14:17:44"
  subject="Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/8a90d2240c3144428951fc8b8cb530a1"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T15:00:48"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/57a3c666e4c3eb4f607f6630601c5bff"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T15:17:38"
  subject="Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/38da3897544cafcf0076ecf8ed64195c"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T18:01:12"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/49d3727f2409ccf2dd98f311cce6ae25"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T18:20:07"
  subject="Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/38a70da8110050e7ef926b81a62c7e61"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T21:05:28"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/1fb2fd518c360a1be5184a64a0f2ee6c"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T21:26:47"
  subject="Re: How to read different ints from a Bigarray?">
</msg>
</msg>
</msg>
<msg 
  url="2009/10/bf5823ce7568616f364570cd8ba70476"
  from="blue storm &lt;bluestorm.dylc@g...&gt;"
  author="blue storm"
  date="2009-10-28T22:48:07"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/4101b452ec63b2748ed42ae54995fa07"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T09:50:35"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/953f05dc40842238508a9582754f2718"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T10:34:50"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
<msg 
  url="2009/10/6511dd596e8b3822f292f446db039088"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-10-29T12:20:49"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/4310df5ec194cc33ea355f8239da4261"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T17:11:08"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/5efd3ac5be44f2f55ec5ca61f3280bb5"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-10-30T20:30:13"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/b49aebddd45e1b64ce359e1fd20405c8"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-11-01T15:11:55"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/635da940c72d170c8317dad01c90ef0b"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-11-01T19:57:50"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/4d025a878558f48af14c5f309995a242"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-11-02T16:11:29"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/27802294c3fc891d0c2fb6388296d1f5"
  from="Mauricio Fernandez &lt;mfp@a...&gt;"
  author="Mauricio Fernandez"
  date="2009-11-02T16:33:27"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/6800529d761a4da0d1d1c7aff4767544"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-11-02T20:27:02"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/11/c237af6592d90c0f97fc6093bb34c20e"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-11-03T13:18:52"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
</msg>
<msg 
  url="2009/11/713525c1fcc41fa56a8d7371779cb6eb"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-11-02T20:48:11"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/10/161893143f67c350977b99d7f97e55a9"
  from="Florian Weimer &lt;fw@d...&gt;"
  author="Florian Weimer"
  date="2009-10-29T20:40:13"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/30586559793975360d90892ea66b67c9"
  from="Gerd Stolpmann &lt;gerd@g...&gt;"
  author="Gerd Stolpmann"
  date="2009-10-29T20:59:07"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/507822c6b31e007dc642e512f676fb95"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T23:43:14"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/1fa25b75a89559ed7c63df5845298c27"
  from="Gerd Stolpmann &lt;gerd@g...&gt;"
  author="Gerd Stolpmann"
  date="2009-10-30T00:43:59"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
</msg>
</msg>
<msg 
  url="2009/10/12b1267c3a1909e9477ed39ab6be37a7"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T23:38:57"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/10/b699fc83fc25d4dfb6ba4705183804af"
  from="Olivier Andrieu &lt;oandrieu@n...&gt;"
  author="Olivier Andrieu"
  date="2009-10-28T15:37:39"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
<msg 
  url="2009/10/02a74313db370b81dd3c6315f7190d57"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T16:05:56"
  subject="Re: How to read different ints from a Bigarray?">
</msg>
</msg>
<msg 
  url="2009/10/99f45aa9c8324508067c19216451bca4"
  from="Gerd Stolpmann &lt;gerd@g...&gt;"
  author="Gerd Stolpmann"
  date="2009-10-28T15:38:04"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
<msg 
  url="2009/10/14d54df8c72e192b79db94d2c1fac31d"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-28T16:10:10"
  subject="Re: How to read different ints from a Bigarray?">
</msg>
<msg 
  url="2009/10/ebf17417fbc6f4e6317a1582dc10cd69"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T18:37:06"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
</msg>
</msg>
<msg 
  url="2009/10/cffc1ff39a3e25f217348767d8336769"
  from="Xavier Leroy &lt;Xavier.Leroy@i...&gt;"
  author="Xavier Leroy"
  date="2009-10-28T17:10:04"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
<msg 
  url="2009/10/39a4e2380bdf79a6b8604c9f1ed8dc03"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-28T19:05:59"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
</msg>
<msg 
  url="2009/10/a8d579c804005ce1954c686973f455af"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T17:05:55"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
<msg 
  url="2009/10/242a11844cb0d850e2c76b2f006e61b1"
  from="Christophe TROESTLER &lt;Christophe.Troestler+ocaml@u...&gt;"
  author="Christophe TROESTLER"
  date="2009-10-29T18:42:39"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
<msg 
  url="2009/10/033810682bfd9b0436bf52c3c97715e7"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T19:03:19"
  subject="Re: [Caml-list] How to read different ints from a Bigarray?">
</msg>
</msg>
<msg 
  url="2009/10/454ba49ae093f226d01d7090512007cf"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-10-29T18:49:00"
  subject="Re: How to read different ints from a Bigarray?">
<msg 
  url="2009/10/e586cb51b535fb11719cb9caa0bf3398"
  from="Goswin von Brederlow &lt;goswin-v-b@w...&gt;"
  author="Goswin von Brederlow"
  date="2009-10-29T23:25:23"
  subject="Re: [Caml-list] Re: How to read different ints from a Bigarray?">
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>

Am Mittwoch, den 28.10.2009, 14:54 +0100 schrieb Goswin von Brederlow:
&gt; Hi,
&gt; 
&gt; I'm working on binding s for linux libaio library (asynchron IO) with
&gt; a sharp eye on efficiency. That means no copying must be done on the
&gt; data, which in turn means I can not use string as buffer type.
&gt; 
&gt; The best type for this seems to be a (int, int8_unsigned_elt,
&gt; c_layout) Bigarray.Array1.t. So far so good.
&gt; 
&gt; Now I define helper functions:
&gt; 
&gt; let get_uint8 buf off = buf.{off}
&gt; let set_uint8 buf off x = buf.{off} &lt;- x
&gt; 
&gt; But I want more:
&gt; 
&gt; get/set_int8 - do I use Obj.magic to "convert" to int8_signed_elt?
&gt; 
&gt; And endian correcting access for larger ints:
&gt; 
&gt; get/set_big_uint16
&gt; get/set_big_int16
&gt; get/set_little_uint16
&gt; get/set_little_int16
&gt; get/set_big_uint24
&gt; ...
&gt; get/set_little_int56
&gt; get/set_big_int64
&gt; get/set_little_int64
&gt; 
&gt; What is the best way there? For uintXX I can get_uint8 each byte and
&gt; shift and add them together. But that feels inefficient as each access
&gt; will range check and the shifting generates a lot of code while cpus
&gt; can usualy endian correct an int more elegantly.
&gt; 
&gt; Is it worth the overhead of calling a C function to write optimized
&gt; stubs for this?
&gt; 
&gt; And last:
&gt; 
&gt; get/set_string, blit_from/to_string
&gt; 
&gt; Do I create a string where needed and then loop over every char
&gt; calling s.(i) &lt;- char_of_int buf.{off+i}? Or better a C function using
&gt; memcpy?
&gt; 
&gt; What do you think?

A C call is too expensive for a single int (and ocamlopt). The runtime
needs to fix the stack and make it look C-compatible before it can do
the call. Maybe it's ok for an int64.

Can you ensure that you only access the int's at word boundaries? If so,
it would be an option to wrap the same malloc'ed block of memory with
several bigarrays, e.g. you use an (int, int8_unsigned_elt, c_layout)
Bigarray.Array1.t when you access on byte level, but an (int32,
int32_unsigned_elt, c_layout) Bigarray.Array1.t when you access on int32
level, but both bigarrays would point to the same block and share data.
This is trivial to do from C, just create several wrappers for the same
memory.

The nice thing about bigarrays is that the compiler can emit assembly
instructions for accessing them. Much faster than picking bytes and
reconstructing the int's on the caml side. However, if you cannot ensure
aligned int's the latter is probably unavoidable.

Btw, I would be interested in your aio bindings if you do them as open
source project.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------

</contents>

</message>

