[erlang-questions] Erlang and Memory management

Hynek Vychodil <>
Thu Jun 2 11:59:01 CEST 2011


Of course not. But you can easily read it in efficiency guide or just
try it and measure. If it would have quadratic time behavior it does
copying, if linear it doesn't. You should learn a lot during this
exercise about Erlang.

On Thu, Jun 2, 2011 at 10:53 AM, Wenqiang Song <> wrote:
> A related question, for code like following:
> test(<<255, T/binary>>) ->
>     ok;
> test(<<_, T/binary>>) ->
>     test(T).
> Does Erlang copy the input binary for each recursion? If the input is huge,
> it would be very low efficient. If so, what should we do?
> Thanks
> Andy
> On Wed, Jun 1, 2011 at 3:28 AM, Paul Meier <> wrote:
>>
>> I'm in a similar situation.  I've got a few large tries, implemented
>> with gb_trees.  I keep them in an orddict, which I'm using as the
>> State variable of a gb_server.  For example:
>>
>> ------
>> init() ->
>>    %% State is an orddict of 3 giant Tries, pre-made and fetched from
>> the filesystem.
>>    {ok, State}.
>>
>> handle_call({keyed_operation_on_large_data, Key}, _From, State) ->
>>    GiantTrie = orddict:find(Key, State),
>>    .... computations using GiantTrie....
>>    {reply, Result, State}.
>>
>> I'm finding that my process is crashing due to inability to mmap, and
>> the erl_crash.dump file tells me that the gen_server's supervisor (or,
>> on occasion, the error_logger) is the one with a prohibitively large
>> Stack+Heap.  Also, I never modify the Tries or the orddict containing
>> them in calls to the gb_server: it's all read-only.
>>
>> Is storing the value in an orddict, or using regular terms as opposed
>> to binaries causing unnecessary copying?  While _I_ know the data is
>> being used in a read-only fashion, is there a place where copying
>> might be occurring because the VM doesn't know this?
>>
>> I was hoping to play with binaries as a next attempt at fixing this
>> (the links in this thread suggest that large binaries are handled more
>> conservatively), but this thread appeared fortuitously, and maybe
>> someone can spot the very likely obvious error that I'm making.
>>
>> I'm grateful for your help, whether in this thread or the others I've
>> enjoyed reading ^_^
>>
>> -Paul
>>
>>
>> On Tue, May 31, 2011 at 11:19 AM, Kostis Sagonas <>
>> wrote:
>> > Robert Virding wrote:
>> >>
>> >> I just want to point out that these rules are BEAM specific and not
>> >> Erlang
>> >> specific.
>> >
>> > Well, this is not correct: the BEAM nowhere specifies that its
>> > instruction
>> > set has to be implemented using a private heap architecture.  In fact,
>> > we
>> > successfully used the BEAM instruction set to implement both a shared
>> > heap
>> > and a hybrid heap implementation.  See:
>> >
>> >  http://user.it.uu.se/~kostis/Papers/heap.pdf
>> >
>> >> So on an implementation with a single heap all data is shared. Now
>> >> there
>> >> aren't currently many single heap implementations, to be exact only
>> >> one,
>> >> erjang (Erlang on the JVM). :-)
>> >
>> > There have been more.  We had an OTP system with a shared heap and the
>> > hybrid heap system was part of OTP for quite a while.  IMO, it's too bad
>> > that it was not maintained when Erlang/OTP was extended to support SMP
>> > architectures.
>> >
>> > Also, the ETOS (Erlang to Scheme) system was based on a shared heap
>> > architecture.
>> >
>> > Kostis
>> > _______________________________________________
>> > erlang-questions mailing list
>> > 
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> >
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com



More information about the erlang-questions mailing list