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
Runtime string allocation/resizing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-06-21 (21:49)
From: Stephane Glondu <steph@g...>
Subject: Re: [Caml-list] Runtime string allocation/resizing
On Tuesday 21 June 2005 13:43, Robert Roessler wrote:
> [...]
> What is the recommended "OCaml" way to deal with this?
> Should I do two caml_alloc_string calls?  One to initially "get" the
> data, and then alloc a second one and copy to it after I know the
> correct length?
> Or would it be considered better practice to use malloc in the C heap
> for the "temp" copy and only do the caml_alloc_string when I know the
> exact size?

The second one is clearly better since the temp copy won't be used by the 
OCaml part. However, maybe there is a better alternative (for example, 
directly allocating in OCaml heap, then setting the string length so that the 
"extra" part is ignored).

Stephane Glondu.