[erlang-questions] simple question about list memory consumption
Fri Jul 6 13:21:26 CEST 2012
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);
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions