A good start when programming efficient is to have knowledge about how much memory different datatypes and operations require. It is implementation dependent how much memory the Erlang data types and other items consume, but here are some figures for the current erts-5.x beam system. The unit of measurement is memory words and as the current implementation is a 32-bit implementation a word is 32 bits.
Datatype | Memory size |
Integer (-16#7FFFFFF < i <16#7FFFFFF) | 1 word |
Integer (big numbers) | 2..N words |
Atom | 1 word |
Float | 3 words |
Binary | 2..5 + data |
List | 2 words per element + the size of each element |
String (is the same as a List of Integers) | 2 words per character |
n-Tuple | (n + 1) words + the size of each element - 1 |
Pid | 1 word |
Port | 1 word |
Reference | 5 words |
Fun | 6 + environment |
Ets table | initially 768 words + the size of each data record. The table will grow when necessary. |
Erlang process | 318 words when spawned |
The Erlang language specification puts no limits on number of processes, length of atoms etc. but for performance and memory saving reasons there will always be limits in a practical implementation of the Erlang language and execution environment. The current implementation has a few limitations that is good to know about since some of them can be of great importance for the design of an application.
ERL_MAX_ETS_TABLES
.