Browse thread
Documentation request: allocation of bigarrays in C
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | sayan@c... |
| Subject: | Documentation request: allocation of bigarrays in C |
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