Atom is just an identifier supported by a virtual machine. The identifier representation is an integer of a machine of the underlying architecture, for example. 4 bytes on 32-bit systems and 8 bytes on 64-bit systems. See Use in the LYSE Book .
The same atom in the same virtual machine always maps to the same identifier (integer). For example, the following tuple:
{apple, pear, cherry, apple}
can be saved as the following tuple in the actual Erlang memory:
{1, 2, 3, 1}
All atoms are stored in one large table, which is never collected with garbage, i.e. as soon as an atom is created in a running virtual machine, it remains in the table until the virtual machine is closed.
Answering your questions:
1. No. The atom id will change between VM starts. If you turn off the virtual machine and restart the tuple over the system, you can get the following identifiers:
{50, 51, 52, 50}
depending on what other atoms were created before loading it. Atoms only live as long as the virtual machine.
2. No. There is only one atom table on the VM. All literal atoms in the module are mapped to their identifiers when loading the module. If a specific atom does not already exist in this table, it is inserted and remains there until the VM reboots.
3. None. Tables with atoms are located on the VM and are separate. Consider a situation where two virtual machines start simultaneously, but they do not know each other. Atoms created in each virtual machine can have different identifiers in the table. If at some point in time one node finds out about other nodes, different atoms will have different identifiers. They cannot be easily synchronized or combined. But atoms are not just sent as textual representations to another node. They are "compressed" in the form of a cache and send everything together in the header. See the distribution header in the communication protocol description. Basically, the header contains atoms used in later terms with their identifiers and textual representation. Then, each term refers to an atom by the identifier specified in the header, and does not transmit the same text every time.
Amiramix
source share