ETS 创造回报值

Posted

技术标签:

【中文标题】ETS 创造回报值【英文标题】:ETS creation return value 【发布时间】:2018-09-12 23:13:28 【问题描述】:

我正在使用 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】:

是的,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.

【讨论】:

非常感谢。我提交了更新文档的拉取请求,对 here。

以上是关于ETS 创造回报值的主要内容,如果未能解决你的问题,请参考以下文章

什么语言创造了左值这个词? [关闭]

消费核弹大数据ZH创造终身价值

构造函数

创造一个用户及其密码

人月神话阅读笔记01

jquery 动态创造div的并创建不同的id值