erlang数据类型atom

来源:互联网 发布:香港青旅 知乎 编辑:程序博客网 时间:2024/05/19 15:41
闲来无事反看下Erlang 数据类型 atom 的结构
/*
 * Atom entry.
 */
typedef struct atom {
    IndexSlot slot;  /* MUST BE LOCATED AT TOP OF STRUCT!!! */
    Sint16 len;      /* length of atom name (UTF-8 encoded) */
    Sint16 latin1_chars; /* 0-255 if atom can be encoded in latin1; otherwise, -1 */
    int ord0;        /* ordinal value of first 3 bytes + 7 bits */
    byte* name;      /* name of atom */
} Atom;

typedef struct index_slot
{
    HashBucket bucket;
    int index;
} IndexSlot;

/*
** This bucket must be placed in top of
** every object that uses hashing!!!
** (Object*) == (Object*) &bucket
*/
typedef struct hash_bucket
{
    struct hash_bucket* next;    /* Next bucket */
    HashValue hvalue;           /* Store hash value for get, rehash */
} HashBucket;

我们能发现, 每个 atom都是被指针链接的, 进程中应尽量避免atom数量迅速增长, 否则内存会被吃尽, 暂不论gc

[{total,139362544},
 {processes,19790716},
 {processes_used,19790596},
 {system,119571828},
 {atom,24622525},
 {atom_used,24604689},
 {binary,27127584},
 {code,22218365},
 {ets,2637648}]
在增加原子一定数量后
[{total,853879208},
 {processes,126928868},
 {processes_used,126928668},
 {system,726950340},
 {atom,272067249},
 {atom_used,271991932},
 {binary,26969144},
 {code,22218365},
 {ets,2637648}]

0 0