<br><div class="gmail_quote">On Mon, Sep 10, 2012 at 12:08 PM, Lukas Larsson <span dir="ltr"><<a href="mailto:lukas@erlang-solutions.com" target="_blank">lukas@erlang-solutions.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
Only the tuple which is the record and the immidiates (i.e. small int,<br>
atom, pid, ref etc) will be copied. All other parts use pointers<br>
internally and the same pointers will be copied into the correct<br>
places within the tuple. So in this case a new 6 word memory block<br>
will be created and filled with the atom undefined and finally the new<br>
counter.<br>
<br>
I think that the compiler does some optimization based on updating<br>
tuples within the same function body, though I've forgotten what it is<br>
it does.<br>
<br></blockquote><div><br></div>This bit? <a href="http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id61731">http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id61731</a><br><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hope that makes sense.<br>
<span class="HOEnZb"><font color="#888888"><br>
Lukas<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, Sep 10, 2012 at 4:27 PM, Max Lapshin <<a href="mailto:max.lapshin@gmail.com">max.lapshin@gmail.com</a>> wrote:<br>
> For example I have such gen_server:<br>
><br>
> -record(state,<br>
> field1,<br>
> field2,<br>
> field3,<br>
> counter = 0<br>
> }.<br>
><br>
><br>
><br>
> handle_info(incr, #state{counter = Counter} = State) -><br>
> {noreply, State#state{counter = Counter + 1}};<br>
><br>
><br>
> Will here whole #state{} be deep-copied with new Counter +1 field, or<br>
> it is possible to guess, that here optimization is possible and just<br>
> "edit" counter field in existing tuple?<br>
><br>
> Is it possible to understand by erlang source code, that State is no<br>
> longer referenced anywhere to avod large allocation and free?<br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br>