addressing a lot of processes
Gaspar Chilingarov
nm@REDACTED
Sat May 21 14:02:38 CEST 2005
Matthias Lang wrote:
> > On 20 May 2005, at 16:23, Gaspar Chilingarov wrote:
>
> > > For now, I've implemented sample manager, which maps IP(string) to PID
> > > using gb_trees. In another hand, I've seen sample in some erlang
> > > sources, to register process under unique name say ip_127.0.0.1,
> > > ip_127.0.0.2 etc.
> > >
> > > This leads to generating the new atoms in runtime, and I'm conscious
> > > that erlang's GC will not clean them if they are unused. Am I right?
>
> IP(string) and IP(atom) aren't the only representations. In this case,
> IP(tuple) would also make sense, and the conversion is easy:
>
> {ok, Tuple} = inet:getaddr(String, inet)
>
> IP(integer) is another possibility, i.e.
>
> {ok, {A,B,C,D}} = inet:getaddr(String, inet),
> Integer = (A bsl 24) + (B bsl 16) + (C bsl 8) + D.
>
> Then you don't have to worry about the atom table _and_ you have a
> useful representation.
>
> Matthias
>
in case if I use atoms I can write smthing like this
try
ip_127_0_0_1 ! { processNewData, SomeData }
catch
Any ->
createAndRegisterNewProcess(127_0_0_1)
ip_127_0_0_1 ! { processNewData, SomeData }
end
This will perform lookup not in Erlang data structure - gb_tree in my
case, but in erlangs internal table, which should be faster.
In case that ~ have limited set of ip's which should be processed, I
think I can avoid trashing of atoms table.
--
Gaspar Chilingarov
System Administrator
t +37491 419763
w www.web.am
e nm@REDACTED
More information about the erlang-questions
mailing list