Version française
Home     About     Download     Resources     Contact us    
Browse thread
FFI: Allocating an array of doubles and initializing it
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Olivier Andrieu <oandrieu@n...>
Subject: Re: [Caml-list] FFI: Allocating an array of doubles and initializing it
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