[erlang-questions] Question about implementation

Daniel Dormont dan@REDACTED
Mon Sep 10 19:35:18 CEST 2012


On Mon, Sep 10, 2012 at 12:08 PM, Lukas Larsson
<lukas@REDACTED>wrote:

> Hello,
>
> Only the tuple which is the record and the immidiates (i.e. small int,
> atom, pid, ref etc) will be copied. All other parts use pointers
> internally and the same pointers will be copied into the correct
> places within the tuple. So in this case a new 6 word memory block
> will be created and filled with the atom undefined and finally the new
> counter.
>
> I think that the compiler does some optimization based on updating
> tuples within the same function body, though I've forgotten what it is
> it does.
>
>
This bit?
http://www.erlang.org/doc/efficiency_guide/commoncaveats.html#id61731


> Hope that makes sense.
>
> Lukas
>
> On Mon, Sep 10, 2012 at 4:27 PM, Max Lapshin <max.lapshin@REDACTED>
> wrote:
> > For example I have such gen_server:
> >
> > -record(state,
> >    field1,
> >    field2,
> >    field3,
> >    counter = 0
> > }.
> >
> >
> >
> > handle_info(incr, #state{counter = Counter} = State) ->
> >    {noreply, State#state{counter = Counter + 1}};
> >
> >
> > Will here whole #state{} be deep-copied with new Counter +1 field, or
> > it is possible to guess, that here optimization is possible and just
> > "edit" counter field in existing tuple?
> >
> > Is it possible to understand by erlang source code, that State is no
> > longer referenced anywhere to avod large allocation and free?
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120910/c24b6d86/attachment.htm>


More information about the erlang-questions mailing list