Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Stefan Monnier" <stefan.monnier@lia.di.epfl.ch>
To: Thorsten Ohl <ohl@crunch.ikp.physik.th-darmstadt.de>
Cc: caml-list@pauillac.inria.fr
Subject: Re: caml (special) light and numerics
Date: Thu, 19 Oct 1995 09:55:28 +0100	[thread overview]
Message-ID: <m0t5qlC-0008TYC@liasg9.epfl.ch> (raw)
In-Reply-To: ohl's message of Wed, 18 Oct 1995 16:41:32 +0100. <9510181541.AA23639@crunch>


> 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






  parent reply	other threads:[~1995-10-19  8:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-10-13 13:20 Thorsten Ohl
1995-10-16 18:20 ` Xavier Leroy
1995-10-17 15:57   ` Thorsten Ohl
1995-10-17 20:00     ` Pierre Weis
1995-10-18 15:41       ` Thorsten Ohl
1995-10-18 18:05         ` Pierre Weis
1995-10-19  8:55         ` Stefan Monnier [this message]
1995-10-19  9:01     ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0t5qlC-0008TYC@liasg9.epfl.ch \
    --to=stefan.monnier@lia.di.epfl.ch \
    --cc=caml-list@pauillac.inria.fr \
    --cc=ohl@crunch.ikp.physik.th-darmstadt.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox