<div dir="ltr"><div>A tuple of 2 elements will take 3 words of memory minimum</div><div><a href="http://beam-wisdoms.clau.se/en/latest/indepth-memory-layout.html#tuple-arityval-0">http://beam-wisdoms.clau.se/en/latest/indepth-memory-layout.html#tuple-arityval-0</a></div><div>tuple1 = [ headerWord, element1, element2 ]<br></div><div><br></div><div>A cons cell has no header word, so an improper list of 1 element and 2nd element as a tail, just 2 values stored side to side<br></div><div>(same as normal list below except that only 1 cons cell is used, 2 words)</div><div>cons1 = [ element1, element2 ]<br></div><div><br></div><div>
<div>A proper list of 2 elements will take 2 cons cells, i.e. 4 words of memory minimum</div><div>cons2 = [ element2, [] ]<br></div><div>cons1 = [ element1, cons2 ]<br></div><div><a href="http://beam-wisdoms.clau.se/en/latest/indepth-memory-layout.html#lists-cons">http://beam-wisdoms.clau.se/en/latest/indepth-memory-layout.html#lists-cons</a><br></div><div><br></div>
</div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-06-29 2:23 GMT+02:00 Dmitry Belyaev <span dir="ltr"><<a href="mailto:be.dmitry@gmail.com" target="_blank">be.dmitry@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>It's a way to reduce memory footprint.</div><div><br></div><div>Tuple of size N is roughly represented in memory as an array [TupleTag, N, TupleElement1, TupleElement2, ..., TupleElementN].</div><div>Compare it to Cons cell representation: [ConsTag, HeadElement, TailElement] - it saves 1 word per structure.<br></div><div class="gmail_extra"><br clear="all"><div><div class="m_7606740003781037632m_2917007213273080743gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Kind regards,<div>Dmitry Belyaev</div></div></div></div>
<br><div class="gmail_quote">On Fri, Jun 29, 2018 at 9:50 AM, Karlo Kuna <span dir="ltr"><<a href="mailto:kuna.prime@gmail.com" target="_blank">kuna.prime@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">dealing with digraph module i have noticed use of improper lists as representations of edges: <br>['$e' | 123]<div><br></div><div>is there a good reason to use improper lists instead of tuple for this and in general </div><div>when is a good idea to use improper lists?? (i can't think of example for justified use)</div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/list<wbr>info/erlang-questions</a><br>
<br></blockquote></div><br></div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>