[ocaml-ctypes] Arrays from C to Ocaml
Jeremy Yallop
yallop at gmail.com
Tue Jan 7 16:04:57 GMT 2014
On 7 January 2014 13:45, Clark Gaebel <cgaebel at janestreet.com> wrote:
> What's the proper way in ctypes to interface with the following api:
>
> void read_some_data(context* ctx, void* buffer, int length);
>
> where read_some_data pulls some private data out of the given opaque context
> and writes it into the given buffer, without blocking internally.
>
> Ideally, I'd want something in OCaml that looks like:
>
> val read_some_data : ctx -> len:int -> string
>
> and the only way I see of doing this is going through bigstring first. But
> this means two copies: one from C -> bigstring and one from bigstring ->
> string.
For the moment ctypes doesn't provide any way to pass OCaml heap
addresses to C, so moving between OCaml strings and C arrays always
involves a copy.
More information about the Ctypes
mailing list