[erlang-questions] calculating memory consumption

Richard O'Keefe <>
Fri Jan 22 07:07:09 CET 2010


On Jan 22, 2010, at 6:28 PM, Jevin Xu wrote:

> Hi,
>
> How to calculate the memory consumption by below record in a 64-bit  
> machine:
>
> -record(aaa ,       {bb   :: 0..16#fff,        % 3 * 4bit BCD
>                          cc   :: 0..16#fff,        % 3 * 4bit BCD
>                          dd   :: 0..16#ffff,       % 16bit
>                          ee   :: 0..16#ff}).       % 8bit

It's a tuple with five slots, one for each field + one for the tag.
According to the efficiency guide, tuples take
2 words + the size of each element,
so this is 7 words, or 56 bytes.
(Plus of course the word needed to point to it.)

On a 32-bit machine, it would be 28 bytes.

You actually have 6 bytes of data.
I would hope that a 6-byte integer would be held as a single
word on a 64-bit machine.  Is that so?
If so, by holding this as a number, you'd save 56 bytes per
"record".

(The efficiency guide says that the range of fixnums is
(-16#7FFFFFF < i <16#7FFFFFF), or 28 bits.  I've always
hoped that that was simply an incomplete edit, and that
64-bit Erlang allowed 60-bit fixnums.  If not, why not?




More information about the erlang-questions mailing list