为什么使用erts_debug原子的内存为零:size/1?

Bla*_*mba 3 erlang

erts_debug:size/1用来计算erlang VM中atom的内存,但我发现输出为零.谁能解释一下原因?

7> erts_debug:size(true).
0
Run Code Online (Sandbox Code Playgroud)

rvi*_*ing 7

原因是原子与原子的数据一起被固定在原子表中,因此整个节点中只有一个原子的副本.这意味着在您的数据中,atom只是原子表中的标记引用,不占用空间.因此,大小为零.

所以这不是一个不一致或错误.


tko*_*wal 5

在文档中,您可以阅读:

%% size(Term)
%%  Returns the size of Term in actual heap words. Shared subterms are
%%  counted once.  Example: If A = [a,b], B =[A,A] then size(B) returns 8,
%%  while flat_size(B) returns 12.
Run Code Online (Sandbox Code Playgroud)

此处的关键字是HEAP。进程具有堆栈和堆。有一个很棒的演示,向您展示创建术语时存储在堆中的内容和存储在栈中的内容(从第8页开始阅读)。

http://www.erlang-factory.com/upload/presentations/467/Halfword_EUC_2011.pdf

基本上,当您创建单个原子时。堆上没有任何东西,堆栈上只有一个字指针。它指向原子表,原子表也消耗内存,并且不会进行垃圾回收(切勿在应用程序中动态创建原子!)。资料来源:http : //www.erlang.org/doc/efficiency_guide/processes.html