title: Algorithm To Calculate Different Types Of Memory
body: <p>I am trying to calculate memory. I have calculated Available, InUse, Free, and Cached with the following code</p>
  
  <pre><code>  ObjectQuery wql = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
              ManagementObjectSearcher searcher = new ManagementObjectSearcher(wql);
              ManagementObjectCollection results = searcher.Get();
  
              //total amount of free physical memory in bytes
              var Available = new ComputerInfo().AvailablePhysicalMemory;
              //total amount of physical memory in bytes
              var Total = new ComputerInfo().TotalPhysicalMemory;
  
              var PhysicalMemoryInUse = Total - Available;
              Object Free = new object();
              foreach (var result in results)
              {
                  //Free amount
                  Free = result["FreePhysicalMemory"];
              } 
              var Cached = Total - PhysicalMemoryInUse - UInt64.Parse(Free.ToString());
  </code></pre>
  
  <p>How can I calculate Standby, Hardware Reserved, and Modified memory as shown in Resource Monitor in windows?</p>
  
  <p><a href="https://i.stack.imgur.com/3NnTl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3NnTl.png" alt="enter image description here"></a> </p>