caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Documentation request: allocation of bigarrays in C
@ 2006-03-31 14:02 sayan
  2006-03-31 17:57 ` [Caml-list] " Dmitry Bely
  0 siblings, 1 reply; 9+ messages in thread
From: sayan @ 2006-03-31 14:02 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2006-04-03 23:45 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-31 14:02 Documentation request: allocation of bigarrays in C sayan
2006-03-31 17:57 ` [Caml-list] " Dmitry Bely
2006-04-01 10:16   ` Li-Thiao-Té Sébastien
2006-04-01 10:30     ` Jonathan Roewen
2006-04-01 14:42       ` Li-Thiao-Té Sébastien
2006-04-02 13:56     ` Dmitry Bely
2006-04-02 20:54       ` Li-Thiao-Té Sébastien
2006-04-03  9:24         ` Dmitry Bely
2006-04-03 23:45         ` Nathaniel Gray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).