ETS创建返回值 [英] ETS creation return value
问题描述
我正在使用Elixir 1.6.3。
我正在使用Elixir中的Erlang :ets
模块,而的返回值让我有些困惑: ets.new/2
函数。
根据文档示例,当调用: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>
那么,自编写文档以来,有什么改变吗?
还是一样,我对引用是什么感到困惑?
是的,返回 ets:new
的值从整数更改为Erlang / OTP 20.0中的引用。从自述文件:
<上课前= lang-none prettyprint-override>
OTP-14094应用程序:stdlib
***潜在的不兼容性***
已优化通过将表标识符
类型从整数更改为引用来进行ETS操作。该引用使
可以更直接地映射到表,而潜在的
锁争用较少,并且尤其可以使表的创建和
删除的伸缩性更好。
ETS表
标识符的不透明类型的更改可能导致代码失败,从而使有关该不透明类型的错误
假设成为错误。
存储在一个Erlang节点上的表的数量*使用*
是有限的。情况不再如此(
的内存使用除外)。先前的默认限制约为
1400个表,可以通过在启动
Erlang运行时系统之前设置
环境变量ERL_MAX_ETS_TABLES来增加此限制。此硬限制已删除
,但无论如何现在设置
ERL_MAX_ETS_TABLES很有用。应该将其设置为与所用表的最大数量近似的
。由于命名表的内部表的大小为
,因此此
的大小为该值。如果使用大量命名表
且未增加ERL_MAX_ETS_TABLES,则命名表查找的
性能将下降。
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?
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.
这篇关于ETS创建返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!