Question

I'm learning Erlang so this is a question to improve my understanding of the Erlang design choices.

Why are the ETS datastructures (dictionary/tree) treated so differently to the Erlang built-in types (lists/tuples etc). That is, they are not garbage collected and they are mutable so all the functions that use them have side-effects. It seems particularly annoying to have to keep track of ETS tables to avoid memory leaks.

Is there a reason that Erlang doesn't also have a dictionary datatype that behaves much more like a list (is immutable and garbage collected)?

Is the presumption that ETS is only used for large database like structures where copying is very expensive, and for anything else you use the O(n) list of tuples for a key/value datastructure?

Was it helpful?

Solution

ETS is more of a database like facility than a data structure. If you want a key value data type, then you can use the dict module, which behaves like any other Erlang term (garbage collected, immutable, etc). There are also other common data structures implemented in the standard library, such as sets and balanced trees. Most of the time, ETS is unnecessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top