更新时间:2023-11-29 09:47:22
根据标准,内存应该是连续的.26.3.7.1 [array.overview] 段落说明(强调我的):
According to the standard the memory should be contiguous. The 26.3.7.1 [array.overview] paragraph states (emphasis mine):
头部定义了一个用于存储固定大小的类模板对象序列.数组是一个连续的容器.一个实例of array 存储 N 个类型为 T 的元素,因此 size() == N 是一个不变的.
The header defines a class template for storing fixed-size sequences of objects. An array is a contiguous container. An instance of array stores N elements of type T, so that size() == N is an invariant.
更新:似乎实现可能包括填充.这些 SO 帖子中有关该主题的更多信息:
std::array的大小是标准定义的吗?
特别是这个答案:
嵌套 std::array 中的数据是否保证连续?
Update: It appears the implementation might include the padding.
More info on the subject in these SO posts:
Is the size of std::array defined by standard?
and specifically this answer:
Is the data in nested std::arrays guaranteed to be contiguous?