0

Possible Duplicate:
What is private bytes, virtual bytes, working set?

I'm reading a project and programmer write this code to check program memory

if ((Process.GetCurrentProcess().WorkingSet64 + Process.GetCurrentProcess().PagedMemorySize64) > (long)2048* (long)1024 * (long)1024)
{
    Program.Log("memory is over 2G! ----- !closed!" );
    Restart();
}

I want to know why there are PagedMemorySize64 and WorkingSet64 for calculating the current memory size.

Is WorkingSet64 not enough?

Is it true?

Fabio
  • 3,020
  • 4
  • 39
  • 62
MHF
  • 511
  • 8
  • 22
  • 2
    He wrote that because he was utterly clueless. Both about how memory works and how to fix the bugs in his code. Use a memory profiler to fix the bug, get rid of this. – Hans Passant Jan 02 '13 at 08:30
  • 99% of the questions have a significant deal of cluelessness. Last comment sounds like a sensibilities issue rather than a helpful comment. Seems like a fair question. Just the semantics are triggering the SO lifestyle peeps. The Microsoft docs for the two values, as written, are not as helpful as they could be toward answering his question or mapping what is really going on with the function in question. – Beeeaaar Nov 29 '18 at 19:46

1 Answers1

-1

Because he belived that the total memory used by the application is the combination of the memory that has been "Paged out" to disk (not using physical memory) and the current "working set" which im assuming he belived was the current total physical memory used by the app.

So: WorkingSet64 (phys mem) + PagedMemorySize64 (mem paged to disk) = total mem allocated

This gets complicated fast and you will find that there is no one real answer to the question: "how much memory am I taking?". It also doesnt help that the .Net docs on these properties are not so good, and the examples less than helpful for knowing what these mean.

If you want to get into it you might have to go read about windows memory management, including page files, shared DLLs, windows memory pages and windows heaps, and how al that works. For example an app can alloc a heap in its virtual memory address space but not commit pages in that heap to mapping to real memory. Someone might ask, which of the two do I want to know about?

Beeeaaar
  • 1,010
  • 9
  • 19