Version française
Home     About     Download     Resources     Contact us    
Browse thread
Documentation request: allocation of bigarrays in C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Li-Thiao-Té_Sébastien <sayan@c...>
Subject: Re: [Caml-list] Documentation request: allocation of bigarrays in C
Dmitry Bely wrote:
> Li-Thiao-Té Sébastien <sayan@crans.org> 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