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 DB7D9BB81 for ; Sun, 2 Apr 2006 22:54:37 +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 k32KsaBT007409 for ; Sun, 2 Apr 2006 22:54:37 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA32531 for ; Sun, 2 Apr 2006 22:54:36 +0200 (MET DST) Received: from rouge.crans.org (rouge.crans.org [138.231.136.3]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k32KsZNh007406 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Sun, 2 Apr 2006 22:54:36 +0200 Received: from localhost (rouge.adm.crans.org [138.231.144.3]) by rouge.crans.org (Postfix) with ESMTP id 858A9BB80; Sun, 2 Apr 2006 22:54:35 +0200 (CEST) Received: from rouge.crans.org ([138.231.144.3]) by localhost (rouge [138.231.144.3]) (amavisd-new, port 10024) with LMTP id 29238-01-25; Sun, 2 Apr 2006 22:54:35 +0200 (CEST) Received: from [192.168.1.10] (ALille-151-1-22-76.w82-127.abo.wanadoo.fr [82.127.235.76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTP id 0A5BFBB6B; Sun, 2 Apr 2006 22:54:34 +0200 (CEST) Message-ID: <44303A0A.9020003@crans.org> Date: Sun, 02 Apr 2006 22:54:34 +0200 From: =?ISO-8859-1?Q?Li-Thiao-T=E9_S=E9bastien?= User-Agent: Debian Thunderbird 1.0.7 (X11/20051017) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Dmitry Bely Cc: caml-list@inria.fr Subject: Re: [Caml-list] Documentation request: allocation of bigarrays in C References: <442D3667.90904@crans.org> <442E5314.9080804@crans.org> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at crans.org X-Miltered: at concorde with ID 44303A0D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44303A0B.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 Dmitry Bely wrote: > Li-Thiao-Té Sébastien 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==NULL 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 know in advance the size of the multiple bigarrays to allocate. This is determined by parsing the file. To speed up the process, the file is parsed on the C side, which is why I want to do GC-friendly memory allocation directly from C. I do not believe that calling Bigarray.Genarray.create within a C parser is a nice way to do things, especially when there is the opportunity to use alloc_bigarray_xxx to allocate memory. NB: I do not return a single bigarray to ocaml, but a list of bigarrays. -- Li-Thiao-Té Sébastien