geometric memory growth

Thomas Lindgren thomasl_erlang@REDACTED
Fri Nov 25 13:17:31 CET 2005



--- Ulf Wiger <ulf@REDACTED> wrote:

> The obvious fix:
> 
>     Channel = State#state.channel,
>     SendF = fun(To, Msg) ->
> 	          msg(Channel,
> 	          ChNo, To, Msg)
> 	      end,
> 
> Now, wouldn't it be great if the compiler could
> figure out how to do this
> at compile-time?

Hoisting the expression out of the fun is only safe if
State is known to be a #state record at this point.
Otherwise, you can get an exception in the wrong
place.

Applying this optimization (hoisting expressions out
of closures) is often a good thing, since we evaluate
the expression once, then can use the closure many
times. There are some counterexamples, though, so a
bit of care is needed to tell when it is useful.

Best,
Thomas



		
__________________________________ 
Yahoo! Music Unlimited 
Access over 1 million songs. Try it free. 
http://music.yahoo.com/unlimited/



More information about the erlang-questions mailing list