list_to_atom和list_to_existing_atom的区别

来源:互联网 发布:淘宝素材店铺招牌120 编辑:程序博客网 时间:2024/06/05 22:30

Erlang atom不参与垃圾回收,一旦创建就不会被移除掉;一旦超出atom的数量限制(默认是1048576) VM就会终止掉.对于一个会持续运行很久的系统,把任意字符串转成atom是很危险的,内存会慢慢被吃光.如果使用的原子是在预期范围内的,比如协议模块的名称,那么可以使用list_to_existing_atom来进行防范,这个方法所产出的atom必须是之前已经创建过的.

例如: 1>list_to_existing_atom("2").

            会报 ** exception error: bad argument
     in function  list_to_existing_atom/1
        called as list_to_existing_atom("2")

      2>list_to_atom("2").

     3>'2'

    4>list_to_existing_atom("2").

   5>'2'


0 0
原创粉丝点击