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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 781A5BB81 for ; Sun, 2 Apr 2006 16:05:33 +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 k32E5WuY004759 for ; Sun, 2 Apr 2006 16:05:32 +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 QAA27168 for ; Sun, 2 Apr 2006 16:05:31 +0200 (MET DST) Received: from mx1.mail.ru (mx1.mail.ru [194.67.23.121]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k32E5V2I017712 for ; Sun, 2 Apr 2006 16:05:31 +0200 Received: from [82.165.180.112] (port=42219 helo=bely) by mx1.mail.ru with asmtp id 1FQ3Co-000Pfk-00 for caml-list@inria.fr; Sun, 02 Apr 2006 18:05:30 +0400 Received: from localhost (HELO BELY) [127.0.0.1] by bely (0.0.0.2) with ESMTP (Classic Hamster Vr. 2.0 Build 2.0.0.1) ; Sun, 02 Apr 2006 17:56:19 +0400 X-Comment-To: =?iso-8859-1?Q?Li-Thiao-T=E9_S=E9bastien?= To: caml-list@inria.fr Subject: Re: [Caml-list] Documentation request: allocation of bigarrays in C References: <442D3667.90904@crans.org> <442E5314.9080804@crans.org> From: Dmitry Bely Date: Sun, 02 Apr 2006 17:56:19 +0400 In-Reply-To: <442E5314.9080804@crans.org> (Li-Thiao-T's message of "Sat, 01 Apr 2006 12:16:52 +0200") Message-ID: User-Agent: Gnus/5.1007 (Gnus v5.10.7) XEmacs/21.5 (windows-nt) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Posting-Agent: Hamster/2.0.0.1 X-Miltered: at concorde with ID 442FDA2C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 442FDA2B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; bigarrays:01 bigarray:01 pointer:01 pointer:01 bigarray:01 genarray:01 alloc:01 genarray:01 arrays:01 bigarrays:01 ocaml:01 reordering:01 higher-level:01 val:01 malloc: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.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Li-Thiao-T=E9 S=E9bastien writes: >>>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. >> If you need GC-controlled bigarray, why simply not to use >> Bigarray.Genarray.create? >> > Why is there a C bigarray allocation function at all then ? :) alloc_bigarray_xxx()? Their primary purpose is to allocate a proxy structure for an external C-allocated data (that cannot be finalized). data=3D=3DNULL behaviour IMHO is not for the final user but only for Bigarray.Genarray.create internal use. > In my case, I want to read a relatively big file (50MB) containing > arrays of floats . I use C functions for the raw speed then pass the > bigarrays to OCaml to do some reordering of the data, and higher-level > processing. You should use Bigarray.Genarray.create then pass the created bigarray to C side using Data_bigarray_val(). Note that the bigarray is allocated with malloc() outside the Ocaml heap. > I do not open the file in Ocaml then send a string to C for parsing, > but rather open the file in C and return the bigarray list to > Ocaml. (cf my previous mistake on creating Ocaml lists in C on this > mailing-list) > > I have hundreds of such files that I may want to load and compare > interactively, so reclaiming unused memory is a big bonus. Sure - Ocaml-allocated bigarrays will be finalized as usual. - Dmitry Bely