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: Dmitry Bely <dbely@m...>
Subject: Re: [Caml-list] Documentation request: allocation of bigarrays in C
Li-Thiao-Té Sébastien <sayan@crans.org> writes:

> 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.

OK, probably the NULL case from alloc_bigarray() comment

/* [alloc_bigarray] will allocate a new bigarray object in the heap.
   If [data] is NULL, the memory for the contents is also allocated
   (with [malloc]) by [alloc_bigarray].
   [data] cannot point into the Caml heap.
   [dim] may point into an object in the Caml heap.
*/

should also be mentioned in the docs. If you believe it's necessary, file
the bug report at http://caml.inria.fr/mantis.

> NB: I do not return a single bigarray to ocaml, but a list of bigarrays.

It's hard to imagine when it's really needed, but probably you have ample
grounds for such design.

- Dmitry Bely