In Erlang, what are the benefits of using ets instead of process dictionary within a process?

ETS is not garbage collected since it is stored in a heap outside of erlang processes. This means that when you put something into ets it is copied into it, and when you take it out, you get a copy in your process. Making lots of ets lookups can then lead to excess consing in your process (but this is only relevant for very high througputs).

The process dictionary is garbage collected. It is stored in the process's own heap. So when you look things up in it you get a reference to the exact same value you put in it. The values stored in the process dictionary are not compacted.

Both approaches are non-pure, i.e. they have side-effects. Yes it is bad, and yes it is not why we have both alternatives.

https://stackoverflow.com/questions/1483550/in-erlang-what-are-the-benefits-of-using-ets-instead-of-process-dictionary-with

猜你喜欢

转载自my.oschina.net/u/855913/blog/1633705