Note: The program is just an example, main questions are just after this.
Suppose, I have a C++
program like this:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>numbers = {4,5,3,2,5,42};
cout<<"-------------------\n";
for (auto x : numbers){
cout<< &x <<endl;
x+=10;
}
cout<<"-------------------\n";
for (vector<int>::iterator it = numbers.begin(); it!=numbers.end(); it++){
cout<< &(*it) <<" "<< *it << endl;
}
return 0;
}
The output is:
-------------------
0x28fed4
0x28fed4
0x28fed4
0x28fed4
0x28fed4
0x28fed4
-------------------
0x3b21a8 4
0x3b21ac 5
0x3b21b0 3
0x3b21b4 2
0x3b21b8 5
0x3b21bc 42
From the memory addresses and increasing values, it is clear that auto
is using the variable x
each time which is in a new memory.
Now, I want to know, is there any way to know (built-in function or something like that):
- How much memory the program used from the beginning to end of its execution?
- What is the maximum memory it used?
- How much memory currently it is using?
I am using C++ in Code::Blocks 13.12 in Windows 8.1