I have been having some trouble figuring out how exactly I get a process\'s ram usage. (How much ram it is currently consuming, not how much is reserved, or its max or min)<
great, I wanted this to get the same as depicted in task manager,and tried:
Process.PrivateMemorySize64
Process.PeakVirtualMemorySize64
Process.PeakPagedMemorySize
Process.PagedSystemMemorySize64
Process.PagedMemorySize64
Process.NonpagedSystemMemorySize64
Process.WorkingSet64
and none of those worked but Performance Counter does !
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = "processNameHere";
memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024);
PC.Close();
PC.Dispose();
thanks a lot !
I found this on msdn and it is working
System.Diagnostics.Process proc = ...; // assign your process here :-)
int memsize = 0; // memsize in KB
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = proc.ProcessName;
memsize = Convert.ToInt32(PC.NextValue()) / (int)(1024);
PC.Close();
PC.Dispose();
If you are purely interested in physical memory, you probably want WorkingSet64, which gives "the amount of physical memory allocated for the associated process." Understand that this value constantly fluctuates, and the value this call gives you may not be up to date. You may also be interested in PeakWorkingSet64, which gives "the maximum amount of physical memory used by the associated process."
Win32 GetSystemInfo function works, too.
It is actually successfully used on practice for array of bytes scanning in the process here in this Memory.dll project: https://github.com/erfg12/memory.dll/blob/042db0cf75e4152a7adf1ea47e6f23f1ad763fb6/Memory/memory.cs#L1909