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 7531FBBFB for ; Tue, 21 Jun 2005 22:43:51 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5LKhpla018384 for ; Tue, 21 Jun 2005 22:43:51 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA02963 for ; Tue, 21 Jun 2005 22:43:50 +0200 (MET DST) Received: from smtp821.mail.sc5.yahoo.com (smtp821.mail.sc5.yahoo.com [66.163.171.7]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j5LKhn2R016700 for ; Tue, 21 Jun 2005 22:43:49 +0200 Received: (qmail 91474 invoked from network); 21 Jun 2005 20:43:48 -0000 Received: from unknown (HELO ?192.168.1.100?) (rftp@pacbell.net@63.194.18.166 with plain) by smtp821.mail.sc5.yahoo.com with SMTP; 21 Jun 2005 20:43:48 -0000 Message-ID: <42B87C09.3020008@rftp.com> Date: Tue, 21 Jun 2005 13:43:53 -0700 From: Robert Roessler Organization: Robert's High-performance Software User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Caml-list Subject: Runtime string allocation/resizing Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 42B87C07.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42B87C05.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; runtime:01 resizing:01 interfacing:01 ocaml:01 alloc:01 alloc:01 malloc:01 heap:01 minor:01 ...:98 data:02 data:02 caml:02 caml:02 btw: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: When dealing with OCaml-to-C-land interfacing, I sometimes am in the position of needing to allocate and fill a string - but only have an upper bound for the length... until after I have already copied the data [from a third-party library function]. 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? Or ? BTW, I am more concerned with longer-term issues like memory fragmentation and "extra" [minor] collections than with raw speed (as in copying the data twice being "evil"). Robert Roessler roessler@rftp.com http://www.rftp.com