STL矢量与阵列 [英] STL Vector vs Arrays

查看:115
本文介绍了STL矢量与阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人对STL

Vector类的处理开销有一个基准,对比C风格的数组?

我非常喜欢使用Vectors,但是我关于放慢我的实时代码减速的偏执狂。任何人都可以放心吗?

Does anyone have a benchmark for the processing overhead of the STL
Vector class, vs a C style array?
I would dearly love to use Vectors, but am paranoid about slowing my
real-time code down. Can anyone reassure?

推荐答案



Havatcha skrev:

Havatcha skrev:
有没有人对STL
Vector类的处理开销有一个基准,而不是C风格的数组?
我非常喜欢使用向量,但是对于减慢我的
真实感到偏执 - 代码下来。任何人都可以放心吗?
Does anyone have a benchmark for the processing overhead of the STL
Vector class, vs a C style array?
I would dearly love to use Vectors, but am paranoid about slowing my
real-time code down. Can anyone reassure?




最理想的是,应该没有任何开销,并且有几个基准测试

来证明这一点(例如查看一篇文章) C / C ++用户期刊
如果我没记错的话,由Andrew Koenig提供
)。最佳演示将

作为您特定配置的基准:尝试(记住

打开所有优化)然后决定std :: vector是否

适合你。


/ Peter



Optimally, there should be no overhead and there are several benchmarks
that demonstrate that (look e.g. for an article in C/C++ Users Journal
by Andrew Koenig if I remember correctly). The best demonstration will
be a benchmark on your particular configuration: try that (remember to
turn all optimizations on) and then decide if std::vector is
appropriate for you.

/Peter


Havatcha写道:
Havatcha wrote:
是否有人对STL
Vector类和C样式数组的处理开销有基准?


即使有人这样做,它又如何帮助?做你自己的。

我非常喜欢使用向量,但我很害怕减慢我的实时代码。有人可以放心吗?
Does anyone have a benchmark for the processing overhead of the STL
Vector class, vs a C style array?
Even if somebody does, how can it help? Do your own.
I would dearly love to use Vectors, but am paranoid about slowing my
real-time code down. Can anyone reassure?




没有人可以放心。在_your_应用程序中进行自己的分析。

任何其他人的测试不适用于_your_particular_使用

容器或数组。


另外,考虑两件事:(a)向量内部存储(和操纵)

一个数组无论如何,所以不要期望太大的差异和(b)向量不是

加快速度,这是为了方便不关心重新分配

数组本身。加速不是在运行时间,它正在开发中 -

时间。


V



Nobody can reassure. Do your own profiling in _your_ application.
Anybody else''s tests are not applicable to _your_particular_ use of the
containers or arrays.

Also, consider two things: (a) vectors internally store (and manipulate)
an array anyway, so do not expect much difference and (b) vector is not
to speed things up, it''s for convenience of not caring about reallocating
the array yourself. The speed-up is not in run-time, it''s in development-
time.

V

< br>

Victor Bazarov写道:
Victor Bazarov wrote:
这是为了方便自己不关心重新分配数组。加速不是在运行时间,而是在开发 -
时间。
it''s for convenience of not caring about reallocating
the array yourself. The speed-up is not in run-time, it''s in development-
time.




你忘记了另一个大的加速。它不仅在开发时间,

,而且在调试时间。你不必担心内存

泄漏/无效指针等等......



You forgot the other big speed-up. It''s not only in development-time,
but in debugging-time. You don''t worry as much about memory
leaks/invalid pointers/etc...


这篇关于STL矢量与阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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