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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 317A7BC0A for ; Wed, 20 Jun 2007 09:13:12 +0200 (CEST) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.176]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5K7DAE8018978 for ; Wed, 20 Jun 2007 09:13:11 +0200 Received: by wa-out-1112.google.com with SMTP id j37so5544waf for ; Wed, 20 Jun 2007 00:13:10 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=R8QVzcV/jyi0xKEUOA0T4cPlwzsBrGR5YiaBDqP4PH1uelSWtro3Dw2bhjW/H8x8XNTzUiv0BLMU/YZmODUM4yOFJFgD+DtCB60MGJLIoHDS4GpqfHMBfsyIP6rDgpe1fYdAZUejPwU10FOvG1lriMZD5SwHXZAMDhhhGOPPw9c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=pvHQ8/TwbDxSO5XDy6pePAHh6SEGR39+66Gp/yubOt25UB8vuzgPqVu7kaSzQ6wzNl/Tazah4i4nfzzKzUGlXkJMJv5Yd7UgztC/BvqjDACeRC2cVI1HAsYLuElnQ10zyuOQiqjcJWHMEEUgUN/Z3s4jXQk3d/5zDZ7J44qsNA4= Received: by 10.115.23.12 with SMTP id a12mr11958waj.1182323590430; Wed, 20 Jun 2007 00:13:10 -0700 (PDT) Received: by 10.114.57.7 with HTTP; Wed, 20 Jun 2007 00:13:10 -0700 (PDT) Message-ID: <95513600706200013m5b03e6caidd4fae873a56f288@mail.gmail.com> Date: Wed, 20 Jun 2007 09:13:10 +0200 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: "Kaspar Rohrer" Subject: Re: [Caml-list] FFI: Allocating an array of doubles and initializing it Cc: caml-list@yquem.inria.fr In-Reply-To: <47EE749E-06C8-4A20-8D38-EE47D43CBCA6@student.ethz.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <47EE749E-06C8-4A20-8D38-EE47D43CBCA6@student.ethz.ch> X-Google-Sender-Auth: 4afde385bd24d139 X-Miltered: at discorde with ID 4678D386.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 ffi:01 allocating:01 initializing:01 ocaml:01 alloc:01 alloc:01 camlprim:01 camlparam:01 val:01 val:01 wosize:01 camlreturn:01 ocaml:01 Hi, On 6/20/07, Kaspar Rohrer 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