erl-interface - ing type question

Shawn Pearce <>
Mon Mar 3 12:55:22 CET 2003

Yes, there is a limit in erts on how many atoms can be assigned.  Its
in the Efficiency Guide, section 7.2 "System Limits":

	The maximum number of atoms is 1048576. 

Also, the atoms are not garbage collected, so once you make that many
atoms in erts, erts just crashes.  In short, the only thing that should
make atoms is your source code.  If you don't write the atom by hand,
you most likely shouldn't use value as an atom.  Thus, external programs
sending in atoms should only send in values as atoms which are hand
coded in the interfacing Erlang as atoms, all other data should be
binary or lists.  Also, avoid list_to_atom/1.

As for your Sybase interface, that's pretty cool.  I think we may
need to start developing a common database access interface, at
least in terms of behavior.  We have mnesia already, I'm going
to do an Oracle one soon it looks like, you guys have a Sybase one.  :)

I'd say you should use atoms for all communication protocol handling,
and use strings/lists/binaries for all data passed back to the database.
In Erlang, atoms were meant to replace #define's in C.

That said, I did a JDBC<->Erlang bridge that mapped certain values
in and out of atoms.  Essentially SQL NULL was mapped to Erlang
'undefined'.  Some of my smaller decode tables in the database that
I felt were never going to exceed say 10 or 20 entries had their
keys mapped to atoms, letting my database bridge translate the entry
back to the key to be stored in the database.  Thus I had tables like:

	CREATE TABLE atomtb1 (
		id		numeric(5,0) not null primary key,
		name	varchar(50) not null

		partner_id	NUMERIC(5,0),
		foreign key (partner_id) references atomtb1(id)

And when reading/writing dat1 records from Erlang partner_id showed
up as atoms whose names were the name column from atomtb1.  This
more or less let me mimic how someone would use and store atoms in
Mnesia, but do so in a non-Erlang database without the bloat of
storing the atom directly as a string in the main data table.

If you do this, be sure you have a very good handle on the growth
of the atomtb1 table, or else you risk running out of atoms in erts.

> We have got a low level api (written in C) conversing between erlang
> and sybase 12.5 (if anyone is interested).  Previously we sent the
> requests in to the api as atoms.  Code such as 
> "(strncmp(ERL_ATOM_PTR(fnp), "rpc", 3) == 0)" was used.
> I would like to enquire regarding the use of atoms in this case
> - is it a good thing or would it be more beneficial to be using
> lists / strings.  Internally in the erlang application we try to
> send most data as lists - as it makes it easier to manipulate. 
> So the first question:  Is atoms a good thing to use for sending
> data to the api?  and also for receiving data from the api?  - I
> recall something about only a fixed number of atoms that can be used
> or some such thing.
> If we want to convert to lists - 
> the output can be done as 
> "colp = erl_format ("{col, ~s, ~s}", datafmt[i].name, coldata[i].value);" 
> the ~s converting to strings instead of ~a - converting to atoms.  
> the question however is - how would we read lists incoming -
> unfortuanately in erl_eterm.h i see Int / Float / PID / Port / Ref
> / Tuple Bin / Cons but no LIST - or am I looking for the wrong type.
> Or would the easiest way be sending atoms in and receiving lists?


  You've been leading a dog's life.  Stay off the furniture.

More information about the erlang-questions mailing list