From: "Olivier Andrieu" <oandrieu@nerim.net>
To: "Kaspar Rohrer" <krohrer@student.ethz.ch>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] FFI: Allocating an array of doubles and initializing it
Date: Wed, 20 Jun 2007 09:13:10 +0200 [thread overview]
Message-ID: <95513600706200013m5b03e6caidd4fae873a56f288@mail.gmail.com> (raw)
In-Reply-To: <47EE749E-06C8-4A20-8D38-EE47D43CBCA6@student.ethz.ch>
Hi,
On 6/20/07, Kaspar Rohrer <krohrer@student.ethz.ch> wrote:
> I'm currently trying to allocate an array of doubles to pass some
> values back to Ocaml. However, documentation on this specific topic
> seems relatively sparse, and thus I'm not sure if the following is
> correct:
it is, except it'd simply use caml_alloc instead of caml_alloc_shr and
let the GC decide in which generation it should allocate the array.
> CAMLprim value ml_create_float_array (value n, value fill)
> {
> CAMLparam2(n, fill);
> CAMLlocal1(arr);
>
> long i;
> long N = Long_val(n);
> double D = Double_val(fill);
>
> arr = caml_alloc_shr(N * Double_wosize, Double_array_tag);
> for (i = 0; i < N; ++i) {
> Store_double_field(arr, i, D);
> }
>
> CAMLreturn(arr);
> }
>
> Any help appreciated.
> Kaspar Rohrer
>
> PS: I'm using Ocaml 3.09.
--
Olivier
prev parent reply other threads:[~2007-06-20 7:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-20 2:47 Kaspar Rohrer
2007-06-20 7:13 ` Olivier Andrieu [this message]
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=95513600706200013m5b03e6caidd4fae873a56f288@mail.gmail.com \
--to=oandrieu@nerim.net \
--cc=caml-list@yquem.inria.fr \
--cc=krohrer@student.ethz.ch \
/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