caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Charles Martin <charles@chasm.org>
To: caml-list@inria.fr
Subject: [Caml-list] compiler storage choice optimization?
Date: Fri, 01 Jun 2001 18:49:29 -0700	[thread overview]
Message-ID: <5.1.0.14.0.20010601182845.03bdc020@chasm.org> (raw)

Here's a simple version of the code that sparks my question:

type t = { mutable value : float }
let double x = { value = x.value *. x.value }
let double_in_place x =
  let x' = double x in
  x.value <- x'.value

When I ocamlopt this code, double_in_place inlines the call to double,
but nevertheless x' gets allocated in the heap.  I was hoping that the
compiler might choose stack allocation instead.

The motivation is to be able to write side-effecting in-place
operations primarily in terms of side-effect-free functions.

Although collecting the youngest generation is very fast, stack
allocation should still be faster, and in numerically intense code
having this kind of storage optimization might allow me to have my
functional cake and eat it quickly, too.

So I guess my question is, is this kind of optimization in the cards?

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


                 reply	other threads:[~2001-06-02  1:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=5.1.0.14.0.20010601182845.03bdc020@chasm.org \
    --to=charles@chasm.org \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).