# How to measure memory used(Windows)?

How to measure memory used in Windows(using win7 x64, vs2010)?

Code example:
``````void test()
{
int N=100*1000*1000;

clock_t t;
t= clock();

std::vector<int> vec;
vec.reserve(N);
vec.resize(N);
for(int i=0;i<n;++i) { vec[i]="10;" } t="clock()-t;" printf("mem: %d \n",sizeof(std::vector<int>)+vec.capacity()*sizeof(int));
printf("test run: %d tics , %f sec \n",t, ((float)t)/CLOCKS_PER_SEC);

getchar();
}</n;++i)></int>``````

Let's say I want to know how much space vector of a certain size.
At the bus stop on the line getchar() look in task manager how much space the program:

Results:
kb N
4280 1M
39504 10M
78636 20M
391752 100M

Something can not be traced exact linear dependence, do I understand correctly that the model here is

UPDATE:
``````void test()
{
int N=10*1000*1000;
int K=10;

clock_t t;
t= clock();

std::vector<std::vector<int>> vec;
vec.reserve(N);
vec.resize(N);
for(int i=0;i<n;++i) { vec[i].reserve(k); vec[i].resize(k); for(int j="0;j<K;++j)" vec[i][j]="10;" } t="clock()-t;" printf("mem: %d \n",sizeof(std::vector<std::vector<int>>)+vec.capacity()*sizeof(int));
printf("test run: %d tics , %f sec \n",t, ((float)t)/CLOCKS_PER_SEC);

getchar();
}</n;++i)></std::vector<int>``````

The resulting ~ 1 Kb 250 000 , which is about 3 times more than 100M vector
Still interested in vmmap heap is shown as 1 piece ~300 MB, and many pieces for 16 192k, a few pieces even smaller, only 68 pieces.
So what are these pieces?
September 19th 19 at 00:21
September 19th 19 at 00:23
The first oddity - reserve, and from then resize. Enough only resize(). In addition, resize, there is a second option, especially to fill the newly created elements. Instead
``````vec.reserve(N);
vec.resize(N);
for(int i=0;i<n;++i) { vec[i]="10;" }< code></n;++i)>``````
```<br / > You can write exactly one call to resize().<br> Second, we should not forget that from the point of view of the OS, the unit returns memory to the application page, and a page is typically 4 kilobytes.```
`Second, we should not forget that from the point of view of the OS, the unit returns memory to the application page, and a page is typically 4 kilobytes. ` what does that mean? hint for leveling? - Dessie commented on September 19th 19 at 00:26
:
Overall, this is an allusion to the need to study how operating systems running in protected mode, organize the work with memory. There is a seminar of Yandex on this topic, for example.
If the program needs to work 2 bytes, Windows will give 4096 bytes, if she needs 4097 bytes, it will get 8192 bytes. In addition, there is the question of what option you've watched - the number of virtual pages or the physical pages of the given application. Because at the time of viewing someone could throw some pages to disk. - Erling_Hansen79 commented on September 19th 19 at 00:29
The link is about Linux. I looked in task Manager ->memory(private working set) now it shows(for 100M) 391744 , looked in the resource monitor
391796 completed
393308 working set
1564 total
391744 private

Tried VMMap https://technet.microsoft.com/en-us/library/dd5355...
there are several other figures - Dessie commented on September 19th 19 at 00:32
: "A few others" - is what? You should also not forget that most C++ implementations use different strategies when allocating memory - small pieces coming together, big - in a separate region. - Erling_Hansen79 commented on September 19th 19 at 00:35
a few others - well, for example in the resource monitor working set 393320, and vmmmap working set 394192. And that the "separate region" ? - Dessie commented on September 19th 19 at 00:38
In some implementations, at startup, the standard library allocates a chunk of memory called the heap and small blocks places already in it, not jerking the operating system requests to allocate the next block. For large blocks is executed a system call and the operating system is requested, there is another set of virtual pages. - Erling_Hansen79 commented on September 19th 19 at 00:41
see, the idea of the meaninglessness reserve / resize a row, you deny it. What about the textbook, Chapter 6 Pieces - neverojatnye in paging page with your vast array. Note that it is stored as N separate pieces of K elements. - Erling_Hansen79 commented on September 19th 19 at 00:44
September 19th 19 at 00:25
Open source vector and look at it overhead (I bet it's 12-24 bytes depending on the platform) and add the size of the allocated memory. - Erling_Hansen79 commented on September 19th 19 at 00:37
so I collect peak memory usage at the end of the program, and I need to know exactly how much vector is. - Dessie commented on September 19th 19 at 00:28
: sizeof(int)*vector.capacity() - Erling_Hansen79 commented on September 19th 19 at 00:31
Take the size occupied by the program to create a vector and then, for Wichita small overhead will be the size. - Dessie commented on September 19th 19 at 00:34

Find more questions by tags C++Standard Template Library