Hello everyone. Let's just move on my problem. Here's the code:
1 2 3 4 5 6 7 8 9
|
#include <iostream>
using namespace std;
int main()
{
int a[999999];
int *ptr=new int;
delete ptr;
return 0;
}
|
Let's say we have a maximum of 4Mb memory limit for our program , retrieved
from the memory of system. If we declare an array of integers of exactly 4MB-4B, that is ,
999999 elements, we have left only one cell of mem. remained, used for
declaration of pointer *ptr of type int. Now all the memory allocated for the program is consumed. But this should
not be a problem when we initialize the pointer with new int, because from what I've seen on the internet,
it shoult take up a memory cell not from the memory of program BUT from the system memory, which is MUCH MORE huger.
Though when I initialize it with new int I'm given the overflow error, which is not what I expected, so it
seems like new int doesn't allocate memory cells from the system memory but from program's. So my question is,
what's really going on with new int? And assuming that new int allocate from program memory, I expected to
get rid of error when I delete it using delete keyword( that is, return it back to the system), which is NOT happening. So I'd also
like to know what's wrong with delete keyword too. Thanks in advance!