[erlang-questions] Accumulator and recursion

Ludovic Coquelle lcoquelle@REDACTED
Mon Nov 20 01:26:26 CET 2006


Hi,
Fairly simple questions about Erlang internal behavior... (I'm learning!)

I have a function which store all the message she get:
memoryloop(PidToSendResult, Memory) ->
    receive
        {store, Data} -> memoryloop(PidToSendResult, [Data|Memory]);
        stop -> PidToSendResult ! Memory
    end.

I wonder:
(1) will the (tail) recursion make a real copy (free/realloc) of data which
doens't change? I mean if I have not only a Pid to pass but a big state
configuration list, should I do the same way?
(2) append an element to a list is supposed to create a new list from the
previous list state adding the element. Again the same question: is it a
real copy of all the data? any hiden optimization? if it is a real copy, is
it another datastructure to use to implement my function "memoryloop" ?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061120/adebbe28/attachment.htm>


More information about the erlang-questions mailing list