Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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.