English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Some suggested improvements to the Graphics and Bigarray modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-09 (23:16)
From: Christopher Quinn <cq@h...>
Subject: [Caml-list] Re: Some suggested improvements to the Graphics and Bigarray modules
>  As a palliative a function for
> inter-converting portions of Bigarrays and strings would be welcome,
> as access to strings is much faster.

If you don't mind giving up a bit of safety the following may help. 

Chris Q.

module UnsafeStringOps = struct
  (* Warning: No bounds checking!!!! Coredump grade hack *)

  let ba2str : ('a,'b,'c) Bigarray.Array1.t -> string =
    fun arr -> Obj.obj (Obj.field (Obj.repr arr) 1)

(* Or more properly:
external ba2str: ('a,'b,'c) Bigarray.Array1.t -> string ="ba2str"

where from C you put:
#include <bigarray.h>
value ba2str(value arr){ return Data_bigarray_val(arr); }

  let blit = String.unsafe_blit
  let fill = String.unsafe_fill
  let set = String.unsafe_set
  let get = String.unsafe_get
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr