From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id DD4E8BBBB for ; Fri, 31 Mar 2006 16:02:18 +0200 (CEST) Received: from electre.pasteur.fr (electre.pasteur.fr [157.99.64.120]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k2VE2ImD032767 for ; Fri, 31 Mar 2006 16:02:18 +0200 Received: from [157.99.164.38] (fennel.sysbio.pasteur.fr [157.99.164.38]) by electre.pasteur.fr (8.12.11/8.12.11) with ESMTP id k2VE2Fm0193086; Fri, 31 Mar 2006 16:02:18 +0200 (CEST) Message-ID: <442D3667.90904@crans.org> Date: Fri, 31 Mar 2006 16:02:15 +0200 From: sayan@crans.org User-Agent: Debian Thunderbird 1.0.7 (X11/20051019) X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Documentation request: allocation of bigarrays in C Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 442D366A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bigarrays:01 bigarray:01 pointer:01 malloc:01 ocaml:01 garbage:01 bigarray:01 pointer:01 malloc:01 sizeof:01 alloc:01 dims:01 camlreturn:01 alloc:01 dims:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.0.3 Hi, Please add the following fact to the Bigarray module documentation (I had to look at the c source header) and/or correct it as necessary : A pointer allocated from C using malloc is not freed by the OCaml garbage collector. If you want to be GC-friendly, use the bigarray allocation macros with a NULL pointer to allocate memory then get a pointer to the data array. Example: Instead of float* carray; carray = malloc(sizeof(float)*size); CAMLlocal1(res); res = alloc_bigarray_dims(BIGARRAY_FLOAT32 | BIGARRAY_C_LAYOUT,1,carray,size); CAMLreturn(res); Write CAMLlocal1(res); res = alloc_bigarray_dims(BIGARRAY_FLOAT32 | BIGARRAY_C_LAYOUT,1,NULL,size); float* carray = Data_bigarray_val(res); CAMLreturn(res); Regards, -- Li-Thiao-Té Sébastien