[erlang-questions] simple question about list memory consumption
Fri Jul 6 16:02:07 CEST 2012
On 07/06/2012 03:27 PM, Francesco Mazzoli wrote:
> At Fri, 6 Jul 2012 15:08:30 +0200,
> Sverker Eriksson wrote:
>> Small enough integers (28/60 bit signed integers) *are* stored as immediates
>> in the list cells.
> How can this be, without some kind of tagging, since Erlang list are
> heterogeneous - which would increase memory overhead anyway?
Because all data is tagged.
> In other words, if I have [foo, 1, bar], if the 1 is unboxed, how does Erlang
> know it is an integer?
Simple - there's a difference between "tagged" and "boxed". Boxed means
the first word is a pointer (also tagged) to a location on the heap
where the real data is stored. An "immediate" like an integer is just
that first word, with a couple of bits used as tags.
More information about the erlang-questions