From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id JAA13852 for caml-redistribution; Thu, 19 Oct 1995 09:58:19 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id JAA13799 for ; Thu, 19 Oct 1995 09:55:46 +0100 Received: from liasg9.epfl.ch (root@liasg9.epfl.ch [128.178.155.46]) by concorde.inria.fr (8.6.10/8.6.9) with ESMTP id JAA20260 for ; Thu, 19 Oct 1995 09:55:42 +0100 Received: from lia.di.epfl.ch by liasg9.epfl.ch with esmtp (Smail3.1.29.1 #28) id m0t5qlC-0008TYC; Thu, 19 Oct 95 09:55 MET Message-Id: From: "Stefan Monnier" To: Thorsten Ohl Cc: caml-list@pauillac.inria.fr Subject: Re: caml (special) light and numerics In-reply-to: ohl's message of Wed, 18 Oct 1995 16:41:32 +0100. <9510181541.AA23639@crunch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 19 Oct 1995 09:55:28 +0100 Sender: weis > 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