<a href="http://www.erlang.org/doc/efficiency_guide/advanced.html">http://www.erlang.org/doc/efficiency_guide/advanced.html</a><div><br dir="ltr"><div>The data structure you want for space efficiency is binary. <br><br>On Friday, July 6, 2012, CGS wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<div><br></div><div>I am puzzled by a behavior I didn't expect, so, if anyone can help to understand it, I would appreciate.</div>
<div><br></div><div>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):</div>
<div>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);</div><div>2. opening an Erlang shell (few MB consumption - stable);</div>
<div>3. executing:</div><div><br></div><div>L = lists:map(fun(_) -> 107 end,lists:seq(1,10000000)), ok.</div><div><br></div><div>where (I know it's obvious, but just for completeness):</div><div>- 107 is representing "k" character;</div>
<div>- the 'ok' atom at the end is for not writing the content of L in the shell;</div><div>- 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).</div>
<div><br></div><div>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).</div>
<div><br></div><div>Erlang shell reports "Erlang R15B01 (erts-5.9.1) [source] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]".</div><div><br></div><div>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.</div>
<div><br></div><div>Regards,</div><div>CGS</div><div><br></div>
</blockquote></div></div><span></span>