Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-08-21 (23:46)
From: Mathias Kende <mathias.kende@e...>
Subject: Re: [Caml-list] caml_copy_string
Le samedi 21 août 2010 à 18:30 -0500, Jeffrey Barber a écrit :
> Is there a way to get a string from C to OCaml without the
> caml_copy_string
> function, or is there a version that doesn't copy the string?

There is no such function in the Caml FFI. You could write one yourself
but then the string must have been specially allocated because you need
to add a one word header to the string and maybe some byte at the end.
So, if you have to exchange strings between OCaml and C, the easiest way
is to always allocate them with the caml_alloc_string function. That way
you can use the pointer returned by String_val in your C code and the
string remains a valid Caml string (except caml does not use zero as the
end of string and will stick to its allocated size).