C# works differently than C++. C# that code wouldn't make sense due to garbage collector. In C#, you allocate and deallocate, which in the end doesn't change anything. In C++, all you do is allocate more and more. The heap keeps growing and it's changing.
In C++, however, there's no such thing.
Code compiled with full release optimizations:
int* p = new int;
000E1002 xor eax,offset __imp_operator new (0E20A0h)
000E1007 push 4
000E1009 call esi
000E100B add esp,4
000E100E jmp main+7 (0E1007h)
The first line is initializing function main.
The second line allocates 4 bytes for int* p pointer variable.
The third line calls "operator new".
The fourth line deallocates 4 bytes of the pointer, since its scope expires.
And the final line commands the program to return to line 2.
That's it. It loops until it fills the memory and crashes.
I've tested your code in VS and you are correct; the compiler doesn't optimize it.
There is a snag though. The assembler code that you list indicates that you compiled this as a 32-bit program. So at most it can only use 2GB of memory. So the heap only grows as far as 2GB and then the program crashes. Compile it as a 64-bit program and it will use as much memory as anyone here is likely to have.
Gonna have to try it again. Tried compiling as 64 bit, however, it woulld still crash at 2 GB. Up until now, I used a .bat file to launch itself and the program. That way any PC would crash within 2 secs .
When i try the above method,my system hangs and wen i allocate a calculated value of memory, my application waits till the memory is available and does its work without throwing any out of memory error.
What i want to do is- since evry process will be allocated a part of memory from os,my application wil also have its set of memory.I want to access its memory from an other process so that wen my application tries to further allocate its memory,there s no memory available and it throws the error.