为什么在 Elixir 中访问元组的大小很快?

Why accessing size of tuple in Elixir is fast?

我在很多地方都读到过,在 Elixir 中查找元组的大小非常快,因为元组存储在连续的内存单元中。但是,对于列表来说,这样做的代价更高,因为需要遍历整个列表才能知道列表的长度。

我不明白如何通过在连续的内存单元中找出元组的大小会更快。你不也必须遍历每个单元格吗?

元组大小已存储。列表长度不是。

A tuple is also a boxed value, so it consists of a Boxed pointer (1 word) to an ARITYVAL header (1 word), after which appear the elements of the tuple.
The arity part of the ARITYVAL header is a 26-bit (on a 32-bit system) integer value containing the number of elements in the tuple.
— https://blog.edfine.io/blog/2016/06/28/erlang-data-representation/