我的VC ++ 2008似乎有缺陷 [英] My VC++ 2008 Seems Flawed
问题描述
{ { 字符 b [64];
char b[64];
int ii;
int ii;
int jj;
向量<字符串> vs; int jj;
vector < string > vs; (jj = 0; jj< 2200000; jj ++)
{ for (jj = 0; jj < 2200000; jj++)
{ (ii = 0; ii< 48; ii ++)
b [ii] = for (ii = 0; ii < 48; ii++)
b[ii] = "0" + rand()%32;
b [ii] = '0' + rand() % 32;
b[ii] = '\ 0' ;
vs.push_back(b); '\0';
vs.push_back(b); } vs.erase(vs.begin(),vs.end()); //这行将花费近10分钟的时间执行?!?! 返回 ;
} return;
}
b [ii] = for (ii = 0; ii < 48; ii++)
b[ii] = + rand ()%32;
b [ii] = '0' + rand() % 32;
b[ii] = ; '\0';
这篇关于我的VC ++ 2008似乎有缺陷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我的VC ++ 2008出现了某些问题,因为执行以下功能将花费超过10分钟的时间.特别令人感兴趣的是擦除方法,该方法可在将近200万个项目上运行近10分钟.谁能发现问题?
避免CrippleTheCpu()
Something isn't right about my VC++ 2008 as the following function will take more than 10 minutes to execute. Of particular interest is the erase method that runs for nearly 10 minutes on a little more than 2 million items. Can anyone spot the problem?
void CrippleTheCpu()
谢谢
Thank you,推荐答案
我的VC ++ 2008出现了某些问题
Something isn't right about my VC++ 2008
如果要擦除整个矢量,请使用vs.clear()方法.
您正在使用 vs.erase(vs .begin(),vs.end());
基本上是什么擦除 [迭代器擦除( 迭代器 _First , 迭代器 _Last ); ] 是,它将删除给定范围内的元素并交换元素(重新排列).对流用于删除一定范围内的元素.
您知道要在字符数组 b 中插入什么吗?每次都是'\ 0'(请参见引用的)
If you want to erase the entire vector use vs.clear() method.
You are uisng vs.erase(vs.begin(), vs.end());
Basically what erase [iterator erase(iterator _First, iterator _Last); ] does is, it removes the elements in the given range and swaping the elements (rearranging). It is given for a convection to delete the elements in a certain range.
Do you know what are you inserting to the character array b? Everytime it is '\0' (See the quoted)