[ocaml-ctypes] How to memcpy?

Andre Nathan andre at digirati.com.br
Wed Jul 27 01:30:45 BST 2016


Hi Jeremy

> Em 26 de jul de 2016, às 19:26, Jeremy Yallop <yallop at gmail.com> escreveu:
> 
> In many cases you'll be able to avoid the call to 'memcpy' by using
> 'allocate' to create an initialized object, like this:
> 
>   let p = allocate int 42 in
>   setf v buffer (coerce (ptr int) (ptr void) p)

For strings it seems from the description at [1] that using this method will cause problems if the C object lives longer than the OCaml object.

Is there a way to copy an OCaml string into the buffer with stock a Ctypes or is memcpy the way to go here?

[1] https://github.com/ocamllabs/ocaml-ctypes/issues/159

Best,
Andre


More information about the Ctypes mailing list