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
Re: caml (special) light and numerics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stefan Monnier <stefan.monnier@l...>
Subject: Re: caml (special) light and numerics

> How can I get around in 
>     val f : float array -> float array
>     let f x =
>       let n = Array.length x in
>       let y = n 0.0 in
> 	for i = 0 to n do
> 	  for j = 0 to n do
> 	    y.(i) <- y.(i) +. a.(i).(j) *. x.(j)
> 	  done
> 	done
> The problem is that I cannot modify `x' in place (even if I know that
> I won't need it later).

>From what I understand, you're concerned more about the fact that "new" might
be slow than about the fact that the code will require two arrays in memory at
the same time (hence having a bigger working set).

You should be aware of the fact that heap allocation is very frequent in caml
and is hence made fairly efficient. In the code above, "new" is very unlikely
to represent more than a few pathetic percents of the time spent in the function
(unless "n" is *very* small (like 0 or 1)).