ETS creation return value

混江龙づ霸主 提交于 2019-12-14 01:27:24

问题


I'm using Elixir 1.6.3. I'm working with the Erlang :ets module in Elixir, and I'm a bit confused by the return value of the :ets.new/2 function.

According to the doc's example, when calling :ets.new(:whatever, []), I should be returned what appears to be an integral value:

iex> table = :ets.new(:buckets_registry, [:set, :protected])
8207

However, when I run the exact same code in iex, I get a reference:

iex(1)> table = :ets.new(:buckets_registry, [:set, :protected])     
#Reference<0.1885502827.460455937.234656>

So, has something changed since the documentation was written? Or is it just the same and I'm confused about what a reference is?


回答1:


Yes, the return value of ets:new was changed from an integer to a reference in Erlang/OTP 20.0. From the README:

  OTP-14094    Application(s): stdlib

               *** POTENTIAL INCOMPATIBILITY ***

               Optimized ETS operations by changing table identifier
               type from integer to reference. The reference enables a
               more direct mapping to the table with less potential
               lock contention and makes especially creation and
               deletion of tables scale much better.

               The change of the opaque type for the ETS table
               identifiers may cause failure in code that make faulty
               assumptions about this opaque type.

               The number of tables stored at one Erlang node *used*
               to be limited. This is no longer the case (except by
               memory usage). The previous default limit was about
               1400 tables and could be increased by setting the
               environment variable ERL_MAX_ETS_TABLES before starting
               the Erlang runtime system. This hard limit has been
               removed, but it is currently useful to set the
               ERL_MAX_ETS_TABLES anyway. It should be set to an
               approximate of the maximum amount of tables used. This
               since an internal table for named tables is sized using
               this value. If large amounts of named tables are used
               and ERL_MAX_ETS_TABLES hasn't been increased, the
               performance of named table lookup will degrade.


来源:https://stackoverflow.com/questions/49633255/ets-creation-return-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!