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: Kaspar Rohrer <krohrer@s...>
Subject: FFI: Allocating an array of doubles and initializing it
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.