为什么unbounded_array比矢量更有效? [英] why is unbounded_array more efficient than vector?

查看:110
本文介绍了为什么unbounded_array比矢量更有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它说这里

的无界阵列类似于
  的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆