为什么unbounded_array比矢量更有效? [英] why is unbounded_array more efficient than vector?
问题描述
它说这里了
的无界阵列类似于
的std ::在矢量可以生长在
规模超过任何固定的约束。然而
unbounded_array旨在最佳
性能。因此unbounded_array
并不像建模序列
的std :: vector所。
The unbounded array is similar to a std::vector in that in can grow in size beyond any fixed bound. However unbounded_array is aimed at optimal performance. Therefore unbounded_array does not model a Sequence like std::vector does.
这是什么意思?
推荐答案
这似乎缺少插入
和删除
方法。因为这些可能是慢,即他们的表现在矢量
实施取决于尺寸()
,他们被省略了以prevent程序员从拍摄自己的脚。
It appears to lack insert
and erase
methods. As these may be "slow," ie their performance depends on size()
in the vector
implementation, they were omitted to prevent the programmer from shooting himself in the foot.
插入
和删除
的标准都需要一个容器被称为一个序列,所以不像矢量
, unbounded_array
不是一个序列。
insert
and erase
are required by the standard for a container to be called a Sequence, so unlike vector
, unbounded_array
is not a sequence.
没有效率,未能成为一个序列上涨,本身。
No efficiency is gained by failing to be a sequence, per se.
然而,它的是的在它的内存分配方案更有效,通过避免向量::容量
一个概念,总是有分配的内存块的内容完全相同的大小。这使得 unbounded_array
对象小,使堆,因为它需要完全一样大的块。
However, it is more efficient in its memory allocation scheme, by avoiding a concept of vector::capacity
and always having the allocated block exactly the size of the content. This makes the unbounded_array
object smaller and makes the block on the heap exactly as big as it needs to be.
这篇关于为什么unbounded_array比矢量更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!