From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA06375; Fri, 6 Aug 2004 13:10:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id NAA07709 for ; Fri, 6 Aug 2004 13:10:04 +0200 (MET DST) Received: from ensim.smartydns22.com (ev1s-67-15-74-65.ev1servers.net [67.15.74.65] (may be forged)) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i76BA2mL005809 for ; Fri, 6 Aug 2004 13:10:03 +0200 Received: from www.ivorykite.com (localhost.localdomain [127.0.0.1]) by ensim.smartydns22.com (8.12.10/8.12.10) with SMTP id i76BA0Mi023451; Fri, 6 Aug 2004 21:10:00 +1000 Received: from 60.246.253.51 (SquirrelMail authenticated user effbiae@ivorykite.com) by www.ivorykite.com with HTTP; Fri, 6 Aug 2004 21:10:00 +1000 (EST) Message-ID: <48478.60.246.253.51.1091790600.squirrel@www.ivorykite.com> In-Reply-To: References: <42110.60.246.254.84.1091604455.squirrel@www.ivorykite.com> Date: Fri, 6 Aug 2004 21:10:00 +1000 (EST) Subject: Re: [Caml-list] what magic is this? From: "Jack Andrews" To: "David Monniaux" Cc: caml-list@inria.fr Reply-To: effbiae@ivorykite.com User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Miltered: at nez-perce with ID 4113670A.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ocamlopt:01 ffi:01 ffi:01 java's:01 optimise:01 struct:01 struct:01 alloc:01 sizeof:01 re-write:01 compiler:01 bigarray:01 ocaml:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > External functions starting with a % are primitives that are > directly compiled by the ocamlopt compiler into specific code, > without the overhead of a function call. oooh - nice. now a request. it would be *really* nice if there were some public %primitives that could be used by the FFI user. i'm thinking they would be similar to the bigarray_ref/set primitives, but would publish a contract for the lib writer. this would be something to set ocaml apart (not that it isn't set apart already) a fast FFI is something that languages lack - i wrote a benchmark for java's JNI that demonstrated the problem of needing to optimise the loop while(next())set(get()); (google for jni benchmark). i'd propose that: - in the C code, the first member of a custom struct is a pointer eg: struct CUST { void *ptr; int size; }; - values are allocated as usual: value vcust=alloc_custom(&ops,sizeof(struct CUST),x,y); - four new primitives are available for use in ml file: external get_int : -> int -> int = "%ffi_get_int" external get_float : -> int -> float = "%ffi_get_float" external set_int : -> int -> int -> unit = "%ffi_set_int" external set_float : -> int -> float -> unit = "%ffi_set_float" it would take me a week to work out how to implement these primitives, but one of you ocaml guys could do it a lot quicker. please? you'd only have to re-write it after i made a complete bodge of it :) thanks in advance, jack. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners