为什么是unbounded_array比向量更高效? [英] why is unbounded_array more efficient than vector?
问题描述
这里说,
无界数组类似于
std :: vector,它可以在
中增长超过任何固定界限。然而
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.
这是什么意思?
推荐答案
似乎缺少 insert
和擦除
方法。因为这些可能是慢的,即它们的性能取决于向量
实现中的 size()
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.
插入
和擦除
不是一个序列本身就没有效率。
No efficiency is gained by failing to be a sequence, per se.
,通过避免 vector :: capacity
的概念并且总是具有所分配的块的大小,其在存储器分配方案中更高效内容。这使得 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屋!