Erlang / Erlang Basics Interview questions
What is ETS?
ETS (Erlang Term Storage) is an in-memory table built into the BEAM for storing large amounts of data that any process can read or write directly, bypassing normal message passing. It's how Erlang handles shared state that would be awkward to keep inside a single process's mailbox loop.
Tab = ets:new(my_table, [set, public]), ets:insert(Tab, {key1, "value1"}), ets:lookup(Tab, key1). %% -> [{key1, "value1"}]
Tables come in four flavors — set, ordered_set, bag, and
duplicate_bag — controlling whether keys are unique and whether entries are ordered. Access
is close to O(1) for set/bag tables since they're hash-based, which makes ETS a
common choice for caches and lookup tables shared across many processes.
More Related questions...