ETS创建返回值

时间:2018-04-03 15:00:49

标签: reference erlang elixir ets

我使用的是Elixir 1.6.3。 我正在使用Elixir中的Erlang :ets模块,我对:ets.new/2函数的返回值感到有点困惑。

根据doc's example,在调用:ets.new(:whatever, [])时,我应该返回看似是整数值的内容:

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

但是,当我在iex中运行完全相同的代码时,我会得到一个参考:

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

那么,自编写文档以来有什么变化吗? 或者它是一样的,我对参考是什么感到困惑?

1 个答案:

答案 0 :(得分:5)

是的,ets:new的返回值已从Erlang / OTP 20.0中的整数更改为引用。来自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.