English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] compiler storage choice optimization?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-06-02 (01:47)
From: Charles Martin <charles@c...>
Subject: [Caml-list] compiler storage choice optimization?
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