Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] what magic is this?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jack Andrews <effbiae@i...>
Subject: Re: [Caml-list] what magic is this?
> 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 : <cust_type> -> int -> int   = "%ffi_get_int"
      external get_float : <cust_type> -> int -> float = "%ffi_get_float"
      external   set_int : <cust_type> -> int -> int -> unit =
      external set_float : <cust_type> -> int -> float -> unit =

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,


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: