caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: sayan@crans.org
To: caml-list@yquem.inria.fr
Subject: Documentation request: allocation of bigarrays in C
Date: Fri, 31 Mar 2006 16:02:15 +0200	[thread overview]
Message-ID: <442D3667.90904@crans.org> (raw)

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


             reply	other threads:[~2006-03-31 14:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-31 14:02 sayan [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=442D3667.90904@crans.org \
    --to=sayan@crans.org \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).