为什么“unbounded_array"比“vector"更有效?

Why is #39;unbounded_array#39; more efficient than #39;vector#39;?(为什么“unbounded_array比“vector更有效?)
本文介绍了为什么“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.

这是什么意思?

推荐答案

似乎缺少 inserterase 方法.由于这些可能是缓慢的",即它们的性能取决于 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.

inserterase 是标准要求的容器被称为序列,因此与 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"更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

What is the proper function for comparing two C-style strings?(比较两个 C 风格字符串的正确函数是什么?)
Image Capture with OpenCV - Select Timeout Error(使用 OpenCV 捕获图像 - 选择超时错误)
SHA256 HMAC using OpenSSL 1.1 not compiling(使用 OpenSSL 1.1 的 SHA256 HMAC 未编译)
How to make a Debian package depend on multiple versions of libboost(如何制作一个Debian包依赖于多个版本的libboost)
Why does strcpy_s not exist anywhere on my system?(为什么我系统上的任何地方都不存在 strcpy_s?)
Simplest way to get current time in current timezone using boost::date_time?(使用 boost::date_time 在当前时区获取当前时间的最简单方法?)