हार्डवेयर सुरक्षित शारीरिक रूप से स्थापित मेमोरी की मात्रा और भौतिक स्मृति की कुल राशि ओएस द्वारा रिपोर्ट के बीच अंतर है।
अन्य जानकारी प्रदर्शन काउंटर द्वारा पुनर्प्राप्त की जा सकती है। मेरे पास नीचे एक उदाहरण वर्ग है, लेकिन पता है कि यह एक मजबूत कार्यान्वयन नहीं है। आप उचित त्रुटि हैंडलिंग और संसाधन सफाई जोड़ना चाहेंगे। हालांकि, जब भी आपको इसकी आवश्यकता हो, इस वर्ग के उदाहरण को कैश करना और मूल्यों को Refresh()
के माध्यम से अपडेट करना काफी अच्छा प्रदर्शन करना चाहिए।
public sealed class MemoryInfo : IDisposable
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetPhysicallyInstalledSystemMemory(out ulong memoryInKilobytes);
private readonly PerformanceCounter availableCounter;
private readonly PerformanceCounter modifiedCounter;
private readonly PerformanceCounter freeCounter;
private readonly PerformanceCounter standbyCoreCounter;
private readonly PerformanceCounter standbyNormalCounter;
private readonly PerformanceCounter standbyReserveCounter;
private ulong osTotalMemory;
public ulong ModifiedBytes { get; private set; }
public ulong InUseBytes { get; private set; }
public ulong StandbyBytes { get; private set; }
public ulong FreeBytes { get; private set; }
public ulong HardwareReserved { get; }
public MemoryInfo()
{
var computerInfo = new ComputerInfo();
osTotalMemory = computerInfo.TotalPhysicalMemory;
ulong installedPhysicalMemInKb;
GetPhysicallyInstalledSystemMemory(out installedPhysicalMemInKb);
this.HardwareReserved = installedPhysicalMemInKb * 1024 - osTotalMemory;
modifiedCounter = new PerformanceCounter("Memory", "Modified Page List Bytes");
standbyCoreCounter = new PerformanceCounter("Memory", "Standby Cache Core Bytes");
standbyNormalCounter = new PerformanceCounter("Memory", "Standby Cache Normal Priority Bytes");
standbyReserveCounter = new PerformanceCounter("Memory", "Standby Cache Reserve Bytes");
freeCounter = new PerformanceCounter("Memory", "Free & Zero Page List Bytes");
availableCounter = new PerformanceCounter("Memory", "Available Bytes");
Refresh();
}
public void Refresh()
{
ModifiedBytes = (ulong)modifiedCounter.NextSample().RawValue;
StandbyBytes = (ulong)standbyCoreCounter.NextSample().RawValue +
(ulong)standbyNormalCounter.NextSample().RawValue +
(ulong)standbyReserveCounter.NextSample().RawValue;
FreeBytes = (ulong)freeCounter.NextSample().RawValue;
InUseBytes = osTotalMemory - (ulong) availableCounter.NextSample().RawValue;
}
public void Dispose()
{
modifiedCounter.Dispose();
standbyCoreCounter.Dispose();
standbyNormalCounter.Dispose();
standbyReserveCounter.Dispose();
freeCounter.Dispose();
}
}
इस तरह से यह कर रही है, पर्फ़ काउंटरों की तरह एक साथ समूहीकृत नहीं कर रहे हैं करने के लिए कमियां हैं, तो आप समय में एक विशिष्ट बिंदु पर सिस्टम स्मृति के एक 'असली' स्नैपशॉट नहीं मिलता है। आप शायद Pdh*
win32 एपीआई फ़ंक्शंस का उपयोग करने के लिए PInvoke का उपयोग करके सुधार कर सकते हैं।
आप इसे WMI का उपयोग करने के लिए भी बदल सकते हैं (डेटा Win32_PerfRawData_PerfOS_Memory
में है) लेकिन मुझे नहीं पता कि यह कैसा प्रदर्शन करेगा।
स्रोत
2016-04-27 19:22:30
"स्टैंडबाय मेमोरी" और "संशोधित मेमोरी" क्या है? – quetzalcoatl
@ संसाधन मॉनीटर से दिखाए गए मानों को स्कॉट करें वे मान हैं जो मैं – nlstack01
के लिए देख रहा हूं यह सुनिश्चित नहीं है कि यह आपके लिए काम करता है या नहीं? https://msdn.microsoft.com/en-us/library/windows/desktop/dn958303(v=vs.85).aspx –