English 中文(简体)
C++ 集装箱履约问题
原标题:C++ Container performance question

What would have better performance, a stl vector, or a dynamic array that s just realloc d everytime I want to add something to it?

使用病媒吗?

如果有人能够解释原因,那将是巨大的。

最佳回答

在我每次想给它增加一点东西时,会有哪些更好的业绩、一种 st的矢量或一种能动的阵列?

病媒已插入摊销的固定时间(因为并非所有时间重新分配,保留按系数1.5(最低))。

因此,根据您的描述,病媒将比重新定位所有时间要快得多。

使用病媒吗?

In the general case: exactly identical. However certain STL implementations generate checks in debug mode that can considerably slow down the use of container iterators.

(脚注多数执行者将病媒/检测器作为<代码>价值_类型*的类型

And if someone could explain why, that would be great.

问题回答

理想优化是邪恶。 做事的标准C++是尽可能使用标准图书馆集装箱。 如果你想要使用符合你的需要的最好集装箱:这里是图表

STL diagram for choosing containers

来源: 詹姆斯·威廉姆斯()

也许有一天需要高度优化和使用动态阵列,但应当少见。 ......一天,你还需要收集多面安全......,因此,......但一般而言,集装箱是走路。

在我每次想给它增加一点东西时,会有哪些更好的业绩、一种 st的矢量或一种能动的阵列?

轨道 在这种情况下,应当成为胜者,因为它确实有t realloc every,时间[轨道担保O(1) 摊销插入时间]。 然而,如果最佳地实施这种用途,则可能类似。

使用病媒吗?

这些内容应当相同,特别是因为病媒:器具通常只是一个阵列或一片薄的包装。

速度没有变化,但<条码>探测器大为安全。 这是因为这些职能只是由您的汇编者确定,但vector。 有许多例外和约束检查(如果你要求的话)是你在使用自己的原始阵列时所看到的。





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签