Why is #39;unbounded_array#39; more efficient than #39;vector#39;?(为什么“unbounded_array比“vector更有效?)
问题描述
这里说那个
无界数组类似于std::vector in that in 可以增长超出任何固定范围的大小.然而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"更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么“unbounded_array"比“vector"更有效?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
