Browse thread
Re: caml (special) light and numerics
- Stefan Monnier
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 Array.new in > > val f : float array -> float array > > let f x = > let n = Array.length x in > let y = Array.new 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)). Stefan