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
[Caml-list] caml_copy_string
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Robert Roessler <robertr@r...>
Subject: Re: [Caml-list] caml_copy_string
Jonathan Roewen wrote:
> I notice than caml_copy_string only works with null terminated
> C-strings. What is the alternative way to copy a random amount of
> char* data that contains embedded nulls into an ocaml string (knowing
> the length of the data)?
> Also, out of curiosity: does caml_copy_string reference the string
> itself, or does it make a full copy of it (no sharing)? IE, does
> modification of the C-string affect the ocaml string?

Use caml_alloc_string(n) to create an *uninitialized* Caml string n 
bytes in length.  At least one zero byte will be provided by the Caml 
runtime at the end (possibly more, based on alignment issues).

caml_copy_string is a full physical copy (terminated by the first 
encountered zero byte) of the supplied string - there is no "sharing".

Robert Roessler