7
struct test_struct
{
test_struct() {}
~test_struct() {}
};
#include <vector>
#include <memory>
#include <cstdio>
int main()
{
printf("ctor begin\n");
{
std::vector<std::unique_ptr<test_struct>> test_vec;
const int count = 100000;
for (auto i = 0; i < count; i++) {
test_vec.emplace_back(new test_struct);
}
printf("dtor begin\n");
}
printf("dtor end\n");
}
我正在使用VS2010,並發現了一些荒謬的性能問題。上面的代碼在調試和發佈版本(ctrl + f5)中都能很好地工作,但是當調試器連接(f5)時,dtor調用unique_ptr類的速度變得難以忍受。結果機器代碼是相當優化的,所以我不認爲它是編譯器問題而不是調試器的問題,但我不知道如何處理它。我的問題是連接調試器時,可笑地減慢unique_ptr dtor調用(msvc)
- 此問題是否可以在您的計算機上重現?
- 這種行爲的原因是什麼?
- 有沒有解決方法?
在每次printf後嘗試刷新。 – Pubby
@Pubby:這不會有什麼區別,只有3個'printf'總數,每個循環迭代都不會有一個。 –
我能夠在我的VS2010快速版上重現這一點。 – RedX