What exactly is memory usage?

Walter Bright newshound at digitalmars.com
Sun Sep 3 13:59:26 PDT 2006


Serg Kovrov wrote:
> Walter Bright wrote:
>> Not necessarily. There's a difference between physical memory and 
>> virtual memory. The OS will automatically take away from the process 
>> any unused physical memory, although the process retains it as virtual 
>> memory. If the process explorer watches physical memory, then that's 
>> what it's seeing.
> I'm not trying to argue here, but to understand. I done some search on 
> subject of memory usage. So far, I see it as I described before - to 
> measure application's memory usage, best way is to watch 'private bytes' 
> counter in Perfmon (or via other tools that (I believe) uses Perfmon, 
> such as Process Explorer or FAR's Process list plugin).

If those tools are measuring physical memory, that has no connection to 
whether memory is returned to the operating system or not.

> For example, quote from http://shsc.info/WindowsMemoryManagement:
>> ... is what's called "private bytes" by the Performance control panel.
>> It's memory that's private to that process; generally it's the amount
>> of RAM the process has asked for in order to store runtime data.
> 
> And as I said before C++'s 'delete' (not sure about all implementations, 
> but at least GCC/mingw and VC++2005) do free memory from this 'private 
> bytes' thing.
> 
> You said it is not really returned to OS, but get in to some pool. Ok, 
> could you explain further, is it my application's pool, or some shared 
> pool?

Your application's pool, which is implemented by the runtime library. 
You can see a sample implementation of this in K+R's "The C Programming 
Language" book. malloc/free/new/delete are just functions that are part 
of your program.


> What I mean, is: my application allocated and used this memory, but not 
> anymore - it has been 'delete'd. Application will not need a new memory 
> from OS for some time, or even possibly never. Can this freed(deleted) 
> memory be used elsewhere? Please note, I talking about mentioned here 
> C++ implementation that actually affect 'private bytes' counter.

To understand this, you really need to understand about how demand paged 
virtual memory works, and the difference between virtual and physical 
memory: http://en.wikipedia.org/wiki/Virtual_memory





More information about the Digitalmars-d mailing list