caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] what magic is this?
@ 2004-08-04  7:27 effbiae
  2004-08-05 16:00 ` David Monniaux
  0 siblings, 1 reply; 3+ messages in thread
From: effbiae @ 2004-08-04  7:27 UTC (permalink / raw)
  To: caml-list

i've started writing a mmap module.  i'm looking at the source to bigarray
to see how it's done. in bigarray.ml, external functions
 Array1.{get,set} are linked to "%bigarray_{ref,set}_1"

1) what's the % -- is this what allows the fast access to the base data?
2) bigarray_ref_1 and bigarray_set_1 are not defined anywhere

hold on... greps...finds...

  bytecomp/translcore.ml:   primitives_table ... "%bigarray_ref_1" ...

aahhh.

i bet i could reuse this in my mmap module.  the question is how?

typedef struct _MM{int fd;void *map;unsigned long size;}*MM;

module Mm = struct
 type ('a,'b)t
 external create: 'a a -> 'b b -> ('a, 'b) t
 external get: ('a, 'b) t -> int -> 'a = "%bigarray_ref_1"
 external set: ('a, 'b) t -> int -> 'a -> unit = "%bigarray_set_1"
...end

any pointers greatly appreciated.


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] what magic is this?
  2004-08-04  7:27 [Caml-list] what magic is this? effbiae
@ 2004-08-05 16:00 ` David Monniaux
  2004-08-06 11:10   ` Jack Andrews
  0 siblings, 1 reply; 3+ messages in thread
From: David Monniaux @ 2004-08-05 16:00 UTC (permalink / raw)
  To: effbiae; +Cc: caml-list

On Wed, 4 Aug 2004 effbiae@ivorykite.com wrote:

> i've started writing a mmap module.  i'm looking at the source to bigarray
> to see how it's done. in bigarray.ml, external functions
>  Array1.{get,set} are linked to "%bigarray_{ref,set}_1"

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.

David Monniaux            http://www.di.ens.fr/~monniaux
Laboratoire d'informatique de l'École Normale Supérieure,
Paris, France

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] what magic is this?
  2004-08-05 16:00 ` David Monniaux
@ 2004-08-06 11:10   ` Jack Andrews
  0 siblings, 0 replies; 3+ messages in thread
From: Jack Andrews @ 2004-08-06 11:10 UTC (permalink / raw)
  To: David Monniaux; +Cc: caml-list

> 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 =
                                                         "%ffi_set_int"
      external set_float : <cust_type> -> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-08-06 11:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-04  7:27 [Caml-list] what magic is this? effbiae
2004-08-05 16:00 ` David Monniaux
2004-08-06 11:10   ` Jack Andrews

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).