I know this is such a freak code, but out of curiosity I did it to see memory usage increase using new operator.
1 2 3 4 5 6 7 8 9 10
int main()
{
char* a;
for (;;)
{
//cout<<&a<<endl;
a = newchar[10];
}
}
As you see line7 is commented. When i run this program, obviously a linear increase in memory usage. I could verify it from windows task manager.
But if I uncomment the line7, I could see in the console that same address is getting printed, which means that I don't see any increase in memory. Why is that?
thanks for the comments... i understood and I changed it to print (void*)a now.
Still with line7 uncommented memory doesn't increase. but when i comment it, i can see memory increasing... that's what i'm concerned about.
Nah, that would be totally random. Your compiler also doesn't optimize the new out, otherwise you wouldn't have an increase in memory useage. Have you tried casting a to an int?