[erlang-questions] simple question about list memory consumption

Magnus Henoch magnus.henoch@REDACTED
Fri Jul 6 14:38:36 CEST 2012


Hm, ignore my previous answer, then; I was under the impression that
small enough integers would be stored as immediates in the
list cell...

----- Original Message -----
> 
> http://www.erlang.org/doc/efficiency_guide/advanced.html
> 
> 
> The data structure you want for space efficiency is binary.
> 
> On Friday, July 6, 2012, CGS wrote:
> 
> 
> Hi everyone,
> 
> 
> I am puzzled by a behavior I didn't expect, so, if anyone can help to
> understand it, I would appreciate.
> 
> 
> Let's consider a string of latin1 characters. When dumped to a file
> on a harddisk it occupies, as expected, 1 B per character. When
> loaded in a variable in Erlang shell, I get about 21 B per character
> (at least free is reporting that). Of course, it is hard to test on
> one character due to changing RAM consumption of other processes.
> So, my test case consisted in (I voided writing down and reading
> from a file in the test case):
> 1. stabilizing the environment (no other processes were started, but
> the OS ones and watching for the RAM consumption stabilization at
> the level of MB - give or take 1MB);
> 2. opening an Erlang shell (few MB consumption - stable);
> 3. executing:
> 
> 
> L = lists:map(fun(_) -> 107 end,lists:seq(1,10000000)), ok.
> 
> 
> where (I know it's obvious, but just for completeness):
> - 107 is representing "k" character;
> - the 'ok' atom at the end is for not writing the content of L in the
> shell;
> - the list [107,107,...] is equivalent to "kk..." string (which
> written in a plain text file it gives 1 B per character as it is
> expected).
> 
> 
> The occupied RAM jumped by 214-217 MB for 10^7 characters (at 10^6
> characters, I got 21 MB, so, it is related to the string length
> only), which gives about 21 B per character (one can compute within
> the errors the exact the size, but I took that value as the minimum
> possible).
> 
> 
> Erlang shell reports "Erlang R15B01 (erts-5.9.1) [source] [smp:4:4]
> [async-threads:0] [hipe] [kernel-poll:false] [dtrace]".
> 
> 
> I know that this isn't a big problem, but I am missing something here
> for sure. Can anyone point what I am missing? Thank you in advance.
> 
> 
> Regards,
> CGS
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
> 

-- 
Magnus Henoch
Erlang Solutions Ltd
http://www.erlang-solutions.com/




More information about the erlang-questions mailing list