caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* FFI: Allocating an array of doubles and initializing it
@ 2007-06-20  2:47 Kaspar Rohrer
  2007-06-20  7:13 ` [Caml-list] " Olivier Andrieu
  0 siblings, 1 reply; 2+ messages in thread
From: Kaspar Rohrer @ 2007-06-20  2:47 UTC (permalink / raw)
  To: caml-list

Hello,

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:

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.


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

* Re: [Caml-list] FFI: Allocating an array of doubles and initializing it
  2007-06-20  2:47 FFI: Allocating an array of doubles and initializing it Kaspar Rohrer
@ 2007-06-20  7:13 ` Olivier Andrieu
  0 siblings, 0 replies; 2+ messages in thread
From: Olivier Andrieu @ 2007-06-20  7:13 UTC (permalink / raw)
  To: Kaspar Rohrer; +Cc: caml-list

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


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

end of thread, other threads:[~2007-06-20  7:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-20  2:47 FFI: Allocating an array of doubles and initializing it Kaspar Rohrer
2007-06-20  7:13 ` [Caml-list] " Olivier Andrieu

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).