caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Markus Mottl" <markus.mottl@gmail.com>
To: "Yaron Minsky" <yminsky@cs.cornell.edu>
Cc: "Sebastien Ferre" <ferre@irisa.fr>,
	caml-list@yquem.inria.fr,
	"Daniel Bünzli" <daniel.buenzli@epfl.ch>
Subject: Re: [Caml-list] marshaling limits
Date: Wed, 17 Jan 2007 17:51:37 -0500	[thread overview]
Message-ID: <f8560b80701171451x3be8a995scef89518d6d10b1@mail.gmail.com> (raw)
In-Reply-To: <891bd3390701171150m601bb382ufc1d05f088281b93@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1858 bytes --]

On 1/17/07, Yaron Minsky <yminsky@cs.cornell.edu> wrote:
>
> Don't quote me on this, but I believe that marshal uses a string in
> bytecode with threads, uses straight malloc with bytecode and no threads,
> and never uses strings in native code.  I'm /very/ unsure about that last
> one, but I am pretty confident that in some cases, whether it uses strings
> depends on whether threads are involved.
>

I think the question is more along the lines "byte code threads" vs. native
(e.g. POSIX) threads rather than "byte vs. native code".  It's true that
byte code threads, which can naturally only be used with byte code, require
an intermediate copy step to OCaml-strings if you want to write to
channels.  That's bad on 32bit platforms due to the size limitations on
strings (< 16MB).

I'd recommend using Bigarrays of characters to marshal out data in cases
where OCaml-strings don't suffice.  The code for this is extremely simple:

  extern CAMLprim int
  caml_output_value_to_block(value v, value v_flags, char *bstr, int len);

  CAMLprim value bigstring_marshal_stub(value v, value v_flags)
  {
    char *buf;
    long len;
    int alloc_flags = BIGARRAY_UINT8 | BIGARRAY_C_LAYOUT | BIGARRAY_MANAGED;
    caml_output_value_to_malloc(v, v_flags, &buf, &len);
    return alloc_bigarray(alloc_flags, 1, buf, &len);
  }

The signature of the OCaml-function is:

  external marshal : 'a -> Marshal.extern_flags list -> t  =
"bigstring_marshal_stub"

Where type "t" is a bigarray of characters with C-layout.

You can even do without the intermediate copying if you know the maximum
size of the marshalled data and preallocate a bigarray for that.  Use
"caml_output_value_to_block" for that purpose.  It's defined in
"byterun/extern.c" of the OCaml-distribution.

Regards,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com

[-- Attachment #2: Type: text/html, Size: 2620 bytes --]

  reply	other threads:[~2007-01-17 22:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-16 20:48 ocaml+twt v0.90 Mike Lin
2007-01-17  9:14 ` marshaling limits Sebastien Ferre
2007-01-17  9:36   ` [Caml-list] " Olivier Andrieu
2007-01-17 15:33   ` Frédéric Gava
2007-01-17 15:41     ` Sebastien Ferre
2007-01-17 16:12       ` Daniel Bünzli
2007-01-17 16:32         ` Olivier Andrieu
2007-01-18  8:14           ` Sebastien Ferre
2007-01-17 16:34         ` Sebastien Ferre
2007-01-17 19:37           ` Jonathan Roewen
2007-01-17 19:50           ` Yaron Minsky
2007-01-17 22:51             ` Markus Mottl [this message]
2007-01-23 20:43 ` [Caml-list] ocaml+twt v0.90 Ingo Bormuth
     [not found]   ` <2a1a1a0c0701231322h48e3af00m9f07371f236fe7c@mail.gmail.com>
2007-01-24 16:09     ` Ingo Bormuth

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=f8560b80701171451x3be8a995scef89518d6d10b1@mail.gmail.com \
    --to=markus.mottl@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=daniel.buenzli@epfl.ch \
    --cc=ferre@irisa.fr \
    --cc=yminsky@cs.cornell.edu \
    /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).