#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;
}
Each iteration of this program uses up 20MB of RAM. Why is it not dispatched by this instruction?
while (!foo.empty())
{
delete [] foo.front();
foo.pop();
}
Perhaps it’s because while you pass the reference of
footoaddSomeContent, andaddSomeContentuses it as the variable namedoutput,addSomeContentis allocating all kinds of memory but never placing those allocations inoutput, so back in main,foois empty.At SO we want to be helpful but we really want people to try to help themselves first. This would be a simple problem for you to have spotted on your own if you have done a little debugging before you posted.