#ifndef UNICODE
#define UNICODE
#endif
#include <iostream>
#include <Windows.h>
#include <queue>
using namespace std;
void addSomeContent(queue<TCHAR*> &output)
{
TCHAR* buffer;
for(int i=0; i < 10000; i++)
buffer = new TCHAR[1000];
}
int main()
{
queue<TCHAR*> foo;
char sign;
beginning:
addSomeContent(foo);
while (!foo.empty())
{
delete [] foo.front();
foo.pop();
}
wcout<<TEXT("Press y to repeat\n");
cin>>sign;
if(sign == 'y' || sign == 'Y') goto beginning;
return 0;
}
该程序的每次迭代都会占用 20MB 的 RAM。为什么它没有被这条指令分派?
while (!foo.empty())
{
delete [] foo.front();
foo.pop();
}