[ocaml-ctypes] Help with probable GC problem

Jeremy Yallop yallop at gmail.com
Thu Dec 21 23:49:16 GMT 2017

On 20 December 2017 at 01:21, Andre Nathan <andre at digirati.com.br> wrote:
> Regarding ocaml-memcpy, would it have the same effect in this case if I
> replaced the "ptr_opt char" parameters in the binding specifications with
> just "string", thus letting ctypes make the copy? In that case, would I
> still need to keep a reference to the strings on the OCaml side?

At the moment, no: if you use a string view ctypes will not keep the
copy alive beyond the lifetime of the C call.

But tying the lifetimes of the string and the copy together is a
reasonable idea, and would match the behaviour of 'funptr', where
keeping an OCaml function alive does keep the corresponding C function
pointer alive.  I've opened an issue to discuss/track the possibility
of changing the behaviour:

More information about the Ctypes mailing list