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
Array copying in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-07-24 (19:47)
From: Adrien <camaradetux@g...>
Subject: Re: [Caml-list] Array copying in OCaml
You can compile with the -unsafe flag. If you're using arrays a lot,
it can easily speed your program by 50%. If your program is array
based, the speedup can be even more important.

Don't assume it could magically make your program behave in a weird
way. When you're trying to access an element which is outside the
bounds of the array, ocaml rises an exception. With the -unsafe flag,
no exception will be risen and you will have no chance to catch it.
Consequently if you're out of bounds, your programm will die. That's
why it is called "unsafe". If you're sure you won't be out of bounds
(or are not trying to catch any exception), you can safely use

If you don't want to affect globally your program, you can also use
Array.unsafe_get or Arra.unsafe_set. I don't know the full list


Adrien Nader

2008/7/24 Raj Bandyopadhyay <>:
> Hi
> I have an application which copies a lot of (small) OCaml arrays using the
> Array library (Array.sub and Array.blit) functions. This is turning out to
> be extremely expensive.
> Is there any general way/trick to reduce the cost of this kind of operation?
> I haven't found a way not to copy as much, because the program semantics
> seems to demand it.
> Thanks
> Raj
> _______________________________________________
> Caml-list mailing list. Subscription management:
> Archives:
> Beginner's list:
> Bug reports: