Version française
Home     About     Download     Resources     Contact us    
Browse thread
Question about float refs.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fabrice Le Fessant <fabrice.le_fessant@i...>
Subject: Re: [Caml-list] Re: Question about float refs.
Ethan Burns wrote, On 09/01/2010 11:54 AM:
> On Wed, Sep 1, 2010 at 4:31 AM, Fabrice Le Fessant
> <fabrice.le_fessant@inria.fr> wrote:
>> If you replace (!r +. 0.) by (!r), you are passing the content of the
>> reference as an argument to the function. Function arguments are not
>> unboxed in ocamlopt, so the compiler sees a boxed occurrence of the
>> float, and so must allocate it. The compiler could decide to have the
>> float both as boxed and unboxed values, but since the reference is
>> modified in the loop, there would be a risk of inconsistency, and so the
>> compiler decides to have only a boxed value, and so the loop is much
>> slower since it has to allocate the float at each iteration (the
>> reference itself is probably not allocated).
> 
> Is there a reason that it can not decide to leave the float unboxed
> until right before the Printf.printf call?  This way it would be
> modified in the loop without any allocations and then would be placed
> in a box only when the box is finally needed.

Yes, that would work. I suppose the reason is just that the analysis to
discover that is much more complex and expensive, and the result is not
always successful, so it was not clear it was worth it for typical OCaml
applications.

--Fabrice