From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id F369BBBFB for ; Tue, 21 Jun 2005 23:49:34 +0200 (CEST) Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [213.186.42.179]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5LLnYgS024179 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Tue, 21 Jun 2005 23:49:34 +0200 Received: (qmail 11232 invoked by uid 503); 21 Jun 2005 21:49:38 -0000 Received: (QMFILT: 1.0); 21 Jun 2005 21:49:38 -0000 Received: from b6.ovh.net (HELO mail15.ha.ovh.net) (213.186.33.56) by 26.mail-out.ovh.net with DES-CBC3-SHA encrypted SMTP; 21 Jun 2005 21:49:38 -0000 Received: from b0.ovh.net (HELO queue-out) (213.186.33.50) by b0.ovh.net with SMTP; 21 Jun 2005 21:49:34 -0000 Received: from mail15.ha.ovh.net (10.0.50.15) by mail15.ha.ovh.net with DES-CBC3-SHA encrypted SMTP; 21 Jun 2005 21:49:32 -0000 Received: from b0.ovh.net (HELO queue-pre) (213.186.33.50) by b0.ovh.net with SMTP; 21 Jun 2005 21:49:32 -0000 Received: from nat6-181.cs.ucdavis.edu (HELO ?192.168.1.131?) (postmaster%glondu.net@169.237.6.181) by ns0.ovh.net with SMTP; 21 Jun 2005 21:49:32 -0000 From: Stephane Glondu To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Runtime string allocation/resizing Date: Tue, 21 Jun 2005 14:49:26 -0700 User-Agent: KMail/1.7.1 References: <42B87C09.3020008@rftp.com> In-Reply-To: <42B87C09.3020008@rftp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200506211449.27483.steph@glondu.net> X-Ovh-Remote: 169.237.6.181 (nat6-181.cs.ucdavis.edu) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Miltered: at concorde with ID 42B88B6E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 runtime:01 resizing:01 ocaml:01 alloc:01 alloc:01 malloc:01 heap:01 ocaml:01 allocating:01 heap:01 steph:98 ...:98 wrote:01 data:02 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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.