English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2005-10-29 (00:34)
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