简体   繁体   English

如何在 Windows 中获取内存缓存?

[英]How do I get the memory cache in Windows?

I have searched around a lot but not really found anything.我已经搜索了很多,但没有真正找到任何东西。 I need the memory cache (on the picture 522 MB).我需要内存缓存(在图片上 522 MB)。 How do I get this value, can someone help me?我如何获得这个价值,有人可以帮助我吗? Screenshot of cache缓存截图

Can i access this via "Win32_OperatingSystem"?`我可以通过“Win32_OperatingSystem”访问它吗?

Thanks for your help :)谢谢你的帮助 :)

Here is the implementation of @Panagiotis Kanavos solution from comments (Program prints values in GB):这是来自评论的@Panagiotis Kanavos解决方案的实现(程序以 GB 为单位打印值):

PerformanceCounter counter1 = new PerformanceCounter("Memory", "Cache Bytes");
PerformanceCounter counter2 = new PerformanceCounter("Memory", "Modified Page List Bytes");
PerformanceCounter counter3 = new PerformanceCounter("Memory", "Standby Cache Reserve Bytes");
PerformanceCounter counter4 = new PerformanceCounter("Memory", "Standby Cache Normal Priority Bytes");
PerformanceCounter counter5 = new PerformanceCounter("Memory", "Standby Cache Core Bytes");
while (true)
{
    Console.Clear();
    long bytes = counter1.NextSample().RawValue +
        counter2.NextSample().RawValue +
        counter3.NextSample().RawValue +
        counter4.NextSample().RawValue +
        counter5.NextSample().RawValue;
    Console.WriteLine(bytes / 1024f / 1024f / 1024f);
    Thread.Sleep(1000);
}

The only issue is that when I try to create the counter for Standby Cache Code Bytes , the exception throws, saying that there is no such counter called Standby Cache Code Bytes .唯一的问题是,当我尝试为Standby Cache Code Bytes创建计数器时,抛出异常,说没有称为Standby Cache Code Bytes的计数器。 So I found a counter named Standby Cache Core Bytes and assumed that it might be just a typo in docs.所以我找到了一个名为Standby Cache Core Bytes的计数器,并认为它可能只是文档中的一个错字。

The description for Standby Cache Core Bytes is: Standby Cache Core Bytes的描述是:

Standby Cache Core Bytes is the amount of physical memory, in bytes, that is assigned to the core standby cache page lists. Standby Cache Core Bytes 是分配给核心备用缓存页列表的物理内存量(以字节为单位)。 This memory contains cached data and code that is not actively in use by processes, the system and the system cache.此内存包含进程、系统和系统缓存未主动使用的缓存数据和代码。 It is immediately available for allocation to a process or for system use.它可立即用于分配给进程或供系统使用。 If the system runs out of available free and zero memory, memory on lower priority standby cache page lists will be repurposed before memory on higher priority standby cache page lists.如果系统用完可用的可用内存和零内存,则优先级较低的备用缓存页面列表上的内存将在优先级较高的备用缓存页面列表上的内存之前重新调整用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM