Reputation: 387
I wrote a simple program trying to see change in memory but there was a none. A straight horizontal line around 20% comes always, whether I run the code or not.
#include<iostream>
using namespace std;
int main()
{
int *m;
int i;
cin>>i;
m = new int[i];
}
Shouldnt memory be allocated for any value of i? And a change in Memory free be shown?
Upvotes: 1
Views: 1115
Reputation: 3917
A number of things might be happening...
So, to eliminate these potential causes you could write something like this...
#include <iostream>
int main(int argc, char* argv[]) {
int x,y;
std::cin >> x;
int* m = new int[x];
for (int i = 0; i < x; i++)
m[i] = i;
std::cin >> y;
std::cout << m[y] << std::endl;
return 0;
}
Then, you should be able to check memory usage before you enter the y
value. I'm not sure what operating system you're using, but you should see the image size and the resident memory of the program increase roughly by 4x
bytes.
Upvotes: 2
Reputation: 5920
There could be plenty of reasons why this is happening:
m
pointer is never used, so it will simply delete new[]
operator call;HeapAlloc
method behaves that way;i
value is too big, there is a possibility that heap manager will be unable to find continuous memory block of such size, so new
operator will raise bad_alloc
exception and your program will be terminated.Upvotes: 3
Reputation: 1
You allocated memory for maximum size of a int. That is 4 bytes. Now lets say that your RAM has 8 GB for example. 4 bytes are about 0.00000005% of 8 GB RAM.
Upvotes: -1