Sunday, 15 July 2012

linux - Memory usage in C++ program, as reported by Gnome resource monitor: confusion -



linux - Memory usage in C++ program, as reported by Gnome resource monitor: confusion -

i looking @ memory consumed app create sure not allocating much, , confused gnome resource monitor showing me. have used next pieces of code allocate memory in 2 separate apps otherwise identical; contain nil other code , scanf() phone call pause execution whilst grab memory usage:

malloc(1024 * 1024 * 100);

and

char* p = new char[1204*1024*100];

the next image shows memory usage of app before , after each of these lines:

now, have read lot (but not enough) memory usage (including this question), , having problem differentiating between writeable memory , virtual memory. according linked question,

"writeable memory amount of address space process has allocated write privileges"

and

"virtual memory address space application has allocated"

1) if have allocated memory myself, certainly has write privileges?

2) linked question states (regarding malloc)

"...which won't allocate memory. (see rant @ end of malloc(3) page details.)"

i don't see "rant", , images show virtual memory has increased! can explain please?

3) if have purely next code:

char* p = new char[100];

...the resource monitor shows both memory , writeable memory have increased 8kb - same when allocating total 1 megabyte! - virtual memory increasing 0.1. happening here?

4) column should looking @ in resource monitor see how much memory app using?

thanks much in advance participation, , sorry if have been unclear or missed have led me find answers myself.

the classes of memory reported gnome resource monitor (and in fact, vast bulk of resource reporting tools) not separate classes of memory - there overlap between them because reporting on different characteristics of memory. of different characteristics include:

virtual vs physical - memory in processes address space on modern operating systems virtual; virtual address space mapped actual physical memory hardware capabilities of cpu; how mapping done complex topic in itself, lot of differences between different architectures memory access permissions - memory can readable, writable, or executable, or combination of 3 (in theory - combinations don't create sense , may not allowed hardware and/or software, point these permissions treated separately) resident vs non-resident - virtual memory system, much of address space of process may not mapped real physical memory, variety of reasons - may not have been allocated yet; may part of binary or 1 of libraries, or info segment has not yet been loaded because programme has not called yet; may have been swapped out swap area free physical memory different programme needed it shared vs private - parts of processes virtual address space read-only (for example, actual code of programme , of libraries) may shared other processes utilize same libraries or programme - big advantage overall memory usage, having 37 different xterm instances running not mean code xterm needs loaded 37 different times memory - processes can share 1 re-create of code

because of these, , few other factors (ipc shared memory, memory-mapped files, physical devices have memory regions mapped in hardware, etc.), determining actual memory in utilize single process, or entire system, can complicated.

c++ linux memory-management gnome

No comments:

Post a Comment