From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 46E43BC0A for ; Wed, 20 Jun 2007 04:47:21 +0200 (CEST) Received: from XSMTP0.ethz.ch (xsmtp0.ethz.ch [82.130.70.14]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5K2lKfs027982 for ; Wed, 20 Jun 2007 04:47:21 +0200 Received: from xfe1.d.ethz.ch ([82.130.124.41]) by XSMTP0.ethz.ch with Microsoft SMTPSVC(6.0.3790.3959); Wed, 20 Jun 2007 04:47:18 +0200 Received: from [10.0.1.3] ([80.219.210.76]) by xfe1.d.ethz.ch over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Wed, 20 Jun 2007 04:47:18 +0200 Mime-Version: 1.0 (Apple Message framework v752.3) Content-Transfer-Encoding: 7bit Message-Id: <47EE749E-06C8-4A20-8D38-EE47D43CBCA6@student.ethz.ch> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: caml-list@yquem.inria.fr From: Kaspar Rohrer Subject: FFI: Allocating an array of doubles and initializing it Date: Wed, 20 Jun 2007 04:47:15 +0200 X-Mailer: Apple Mail (2.752.3) X-OriginalArrivalTime: 20 Jun 2007 02:47:18.0144 (UTC) FILETIME=[511CB800:01C7B2E5] X-Miltered: at concorde with ID 46789538.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ffi:01 allocating:01 initializing:01 ocaml:01 camlprim:01 camlparam:01 val:01 val:01 alloc:01 wosize:01 camlreturn:01 ocaml:01 caml:02 seems:03 float:03 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.