[erlang-questions] memory allocation and constant pool behavior

Paolo Negri paolo.negri@REDACTED
Thu May 19 09:23:52 CEST 2011


Dear list

Given the following module

-module(example).
-export([get_configuration/1]).

get_configuration(Position) ->
  Configurations = {{2,3}, {4,1}, {9,7}, {2,1}},
  ConfigurationElement = element(Position, Configurations),
  Constant = {10, 9},
  {ConfigurationElement, Constant}.

I'm trying to understand what happens exactly from a memory allocation
point of view when the function get_configuration gets called, here's
an example call

2> Value = example:get_configuration(2).
{{4,1},{10,9}}

my understanding is that Configurations and Constant will reside in
the constant pool so they won't be allocated at each single execution,
but what I'm looking for is the memory overhead of building the
resulting tuple.
According to the efficiency guide [1] the size of the resulting tuple is

2 words for the containing tuple
4 words for the the inner tuples
4 words for the integers

which results in 10 words total, but how many new words will actually
be allocated at the moment of invoking the function?

1. http://www.erlang.org/doc/efficiency_guide/advanced.html

Thanks for your answers.

Paolo



More information about the erlang-questions mailing list