[zeromq-dev] Introducing Caravan: Simple, Faithful ZMQ-Bindings for Objective Caml (Pedro Borges)
Guillaume Yziquel
guillaume.yziquel at citycable.ch
Mon Apr 4 13:31:32 CEST 2011
Le Monday 04 Apr 2011 à 12:17:01 (+0100), Pedro Borges a écrit :
> On Mon, Apr 4, 2011 at 5:51 AM, Pieter Hintjens <ph at imatix.com> wrote:
> > On Mon, Apr 4, 2011 at 4:24 AM, Brian Ledger <bpl29 at cornell.edu> wrote:
>
>
> > * It's profitable to map libzmq's API closely (including to keep
> > zero-copy functionality) but it's also profitable to build
> > abstractions on top.
>
> Unfortunately implementing zero-copy in ocaml is impossible, AFAIK,
> without blocking every other thread. If another thread makes an
> allocation the GC might move the string you are trying to send.
Not so.
There are multiple solutions. You can allocate your stuff out of the GC,
and the GC will not compact the heap that it doesn't own. You also the
cute caml_register_generational_global_root function if you want buffers
that are sort of fixed. There is also the fact that when OCaml code
enters a C stub, there is no OCaml code running at the same time (global
master lock mechanism). There are multiple tricks to use... including
knowledge of the points where the GC allocates, how to keep holding to a
GC root while releasing the master lock inside the C stub.
The one that's really tough and unsafe is using memory on the call
stack...
--
Guillaume Yziquel
More information about the zeromq-dev
mailing list