为什么“unbounded_array"比“vector"更有效? [英] Why is 'unbounded_array' more efficient than 'vector'?

查看:34
本文介绍了为什么“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"更有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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