为什么 Erlang 中 atom 占用的内存不取决于它的长度?

Why doesn't memory taken by atom in Erlang depend on its length?

据说 Erlang 原子在 space 中只占用 4 或 8 个字节,无论它们有多长。 他们怎么做到的?真的不耗内存吗?

Is it truly no consuming memory?

一个原子指的是一个原子table的ID,它也消耗内存并由名为BEAM, which is the virtual machine at the core of the Erlang Open Telecom Platform OTP的Erlang VM管理。

此 ID 由机器整数表示(在 32 位系统上为 4 个字节,在 64 位系统上为 8 个字节),并且可以在 VM 关闭后重新启动时更改,并且包含这些原子的元组被重新实例化.

原子文本本身为这个 table 中的每个唯一原子存储一次。原子 table 未被垃圾回收。

一个原子中的字符限制为 255,默认情况下,最大原子数为 1048576。可以使用 +t 选项提高或降低此限制。

请参考官方文档here and there了解更多关于原子的详细信息。

有关数据类型的一般信息,您可以阅读 this article