<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
* passing a string using 'string' makes a copy in either direction.<br>
Furthermore,<br>
<br>
- the copy created when passing a string from OCaml to C lives for<br>
the lifetime of the C call.<br>
(It's possible this will be strengthened in the future:<br>
<a href="https://github.com/ocamllabs/ocaml-ctypes/issues/556" rel="noreferrer" target="_blank">https://github.com/ocamllabs/<wbr>ocaml-ctypes/issues/556</a>)<br>
<br>
- the copy created when passing a string from C to OCaml is a<br>
regular OCaml string, subject to usual GC behaviour. Ctypes makes no<br>
attempt to deallocate the memory used by the original C string.<br></blockquote><div><br></div><div><br></div><div>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? </div><div><br></div><div>Silly example:</div><div><br></div><div>char * foo (char * p) { return (p+1); }</div><div><br></div><div>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?</div><div><br></div><div>-Andy</div><div><br></div><div><br></div><div> </div></div></div></div>