论坛首页 综合技术论坛

关于register(some_atom, Pid)的疑问

浏览 9947 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-03-24  
晚上看到register(),知道可以通过register(process_atom, Pid)注册一个进程,于是在使用的时候,可以直接 process_atom ! Msg. 可是刚才不小心冒出疑问,我想问的是,这个process_atom在什么范围有效,是同一个erlang的虚拟机,还是可以多个?如果process_atom表示的进程已经退出,再注册是否就会异常;当注册的进程已经结束后,是否这个process_atom就失效了?

问题儿童,还请多见谅
   发表时间:2007-03-24  
可能大致明白一点了,刚才发现原来还有 {process_atom, Process_Node} ! Msg. 这种用法。
0 请登录后投票
   发表时间:2007-03-24  
erlang的atom是有数量限制的,不过一般的程序都不用考虑这个问题.只是你不要没有限制地使用list_to_atom这样的函数,因为程序无限制的从list中转换atom会使得atom 表溢出.一般可以使用list_to_exit_atom来避免这个问题.
0 请登录后投票
   发表时间:2007-03-24  
回帖专用 写道
erlang的atom是有数量限制的,不过一般的程序都不用考虑这个问题.只是你不要没有限制地使用list_to_atom这样的函数,因为程序无限制的从list中转换atom会使得atom 表溢出.一般可以使用list_to_exit_atom来避免这个问题.

atom居然有数量限制,atom数量太多会导致atom表溢出,这个实在让我太吃惊了。不明白为什么Erlang中或者说其实现会做这么一个限制?

另外, list_to_atom我简单的理解就是把一个list转换成atom,但是list_to_atom和list_to_exit_atom的区别是什么?
0 请登录后投票
   发表时间:2007-03-25  
按照我的理解,atom类似Ruby里面的symbol,从底层角度来说是一个指针,这点可以从Port中对应的类型那里可以看得到。
此外我找不到list_to_exit_atom这个函数,3楼的能否解释一下?
0 请登录后投票
   发表时间:2007-03-26  
list_to_existing_atom(String) -> atom()
0 请登录后投票
   发表时间:2007-03-26  
list_to_existing_atom(String) -> atom()

Types:

String = string()

Returns the atom whose text representation is String, but only if there already exists such atom.

Failure: badarg if there does not already exist an atom whose text representation is String.

这样说来,它的作用在于将接收到的外来字符串转换为atom时使用
    try list_to_existing_atom(String)
    catch Class:Error ->
        % 异常处理
    end
0 请登录后投票
   发表时间:2007-03-26  
晕了.我的理解是Erlang中没有其他语言中的String这种类型,为什么突然多了这么一种数据类型了呢?

还麻烦问一下楼上的,我看到的捕获异常的写法是

case catch list_to_existing_atom(List) of
  class:Error -> ###异常处理
end.


有你写的:
try list_to_existing_atom(String) 
catch Class:Error -> 
% 异常处理 
end 


那种写法吗?我没见过

0 请登录后投票
   发表时间:2007-03-26  
引用
try Expr
catch
    [Class1:]ExceptionPattern1 [when ExceptionGuardSeq1] ->
        ExceptionBody1;
    [ClassN:]ExceptionPatternN [when ExceptionGuardSeqN] ->
        ExceptionBodyN
end



引用
catch Expr


两种语法都是可以的
0 请登录后投票
   发表时间:2007-03-26  
Erlang有String这种数据类型吗?我一直以为"This is not a data type of string"归属于数据类型列表,只不过是一个整数列表,但并不是另外一种叫做String的数据类型.
0 请登录后投票
论坛首页 综合技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics