Erlang Central

Atom Table

Revision as of 08:29, 2 September 2006 by Rvg (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Erlang VM stores all the atoms defined in all the modules in a global atom table. There is a maximum number of atoms that each VM can store. The upper limit by default is atom_tab (max=1048576).This means the VM can only handle a total of 1048576 different atoms. This should be quite enough in any normal system. It is possible to reach this number if you use Dynamic Atoms. This happens when you dynamically constructs atoms by using the list_to_atom function. It is strongly discouraged to use this. Once I saw some code that stored strings in mnesia as atoms. It basically did this:

TheString = "Something to store",
TheAtom = list_to_atom(TheString),
...(store in mnesia)...

...(load from mnesia)...
SomeOtherString = atom_to_list(TheStoredAtom)

It is not a good idea to do this. You can find out how much memory the atom table uses in the erlang VM:

Eshell V5.3  (abort with ^G)
1> memory(atom).
199729
2> memory(atom_used).
175323