[ocaml-ctypes] Help with strings

Andy Ray evilkidder at gmail.com
Thu Dec 28 00:09:23 GMT 2017


>
>
>
>   * passing a string using 'string' makes a copy in either direction.
> Furthermore,
>
>     - the copy created when passing a string from OCaml to C lives for
> the lifetime of the C call.
>       (It's possible this will be strengthened in the future:
> https://github.com/ocamllabs/ocaml-ctypes/issues/556)
>
>     - the copy created when passing a string from C to OCaml is a
> regular OCaml string, subject to usual GC behaviour.  Ctypes makes no
> attempt to deallocate the memory used by the original C string.
>


In the case where a C function takes and returns the same string, does a
signature of [string @-> returning string] also work?  In other words, does
the input string live long enough to ensure the output string is created?

Silly example:

char * foo (char * p) { return (p+1); }

I guess this gets more complex with structures and the like.  More
generally do the arguments to a function call live long enough to create
[view]s of a returned value?

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/ctypes/attachments/20171228/6af6dd70/attachment.html>


More information about the Ctypes mailing list