Atom pollution

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Tue Feb 22 13:01:15 CET 2005


As a general principle, you should make sure that your
atom-producing functions operate on a finite set of 
possible atoms.

In other words, if String in your example is something that 
is received from the outside, you have an infinite set of 
possible atoms, which is not good. Then, I would try to 
re-write the code as:

a("hello")   -> b(hello);
a("ciao")    -> b(ciao);
a("bonjour") -> b(bonjour).

- if at all possible.

/Uffe

> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED]On Behalf Of Corrado Santoro
> Sent: den 22 februari 2005 10:45
> To: erlang-questions@REDACTED
> Subject: Atom pollution
> 
> 
> Dear all,
> 
> I've read that atoms are not garbage collected. But suppose I use the 
> following code:
> 
> a(String) -> b(list_to_atom(String)).
> 
> b(hello) -> ...
> b(ciao) -> ...
> b(bonjour) -> ...
> 
> 
> String can be "hello", "ciao" or "bonjour".
> 
> What happens each time a/1 is called? Is a new atom created 
> each time or 
> there is a sort of "atom hash"?
> 
> Regards,
> --Corrado
> 
> -- 
> ======================================================
> Eng. Corrado Santoro, Ph.D.
> 
> University of Catania - Engineering Faculty
> Department of Computer Science and
> Telecommunications Engineering
> Viale A. Doria, 6 - 95125 CATANIA (ITALY)
> 
> Tel: +39 095 7382380           Fax: +39 095 7382397
>       +39 095 7382365
>       +39 095 7382364
> 
> EMail: csanto@REDACTED
> Personal Home Page:
>              http://www.diit.unict.it/users/csanto
> 
> NUXI Home Page:
>              http://nuxi.iit.unict.it
> ======================================================
> 
> 



More information about the erlang-questions mailing list