为什么"unbounded_array"比"vector"更有效? [英] 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
和erase
方法.由于它们可能是缓慢的",即它们的性能取决于vector
实现中的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.
insert
和erase
称为序列容器,因此与vector
不同的是,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.
但是,它通过避免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"比"vector"更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!