获得自由RAM [英] Getting free RAM

查看:77
本文介绍了获得自由RAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所有,

我正在研究一些因性能原因而缓存数据的软件,但我们不希望该缓存阻止其他程序(或部分程序)同样的程序)从饥饿。所以,我想弄清楚如何做以下两件事之一:

I am working on some software that caches data for performance reasons, but we don't want that cache to prevent other programs (or parts of the same program) from starving. So, I would like to figure out how to do one of two things:

- 弄清楚我们的免费物理内存是否正常运行。这样,如果我们运行不足,我们就可以开始转储缓存了。我尝试使用GlobalMemoryStatusEx(),但它总是将所有值设置为荒谬的(例如

ullAvailPhys   =       14757395258967641292
)。我也尝试过拨打

- Figure out when we are getting low on free physical memory. This way, if we are running low, we can start dumping cache. I tried using GlobalMemoryStatusEx(), but it always sets all values to something ridiculous (like ullAvailPhys =        14757395258967641292). I also tried calling

    gLowMemHandle = CreateMemoryResourceNotification(LowMemoryResourceNotification )

    gLowMemHandle = CreateMemoryResourceNotification( LowMemoryResourceNotification  )

然后

    QueryMemoryResourceNotification(gLowMemHandle,& result),

    QueryMemoryResourceNotification( gLowMemHandle, &result ),

但返回的结果始终为0.那么,实际获得剩余的物理RAM量的方法是什么?



but the result that comes back is always 0. So, any way to actually get the amount of physical RAM that is left?

- 分配失败时获取回调。我可以使用set_new_handler(),除了它在操作系统开始警告我们内存不足后调用得很好。它也只适用于new运算符,而不适用于malloc(或更低级别的OS特定调用)。



- Get a callback when an allocation fails. I can use set_new_handler(), except that it gets called well after the OS starts warning us about low memory. It also only works with the new operator, and not with malloc (or lower-level OS-specific calls).

那么,任何想法为什么这些功能都没有像我期望的那样表现,或者建议我可以采取哪些不同的做法?
b
$ b干杯,

So, any idea why these functions are not behaving as I expect, or suggestion as to what I might be able to do differently?

Cheers,

Dave

推荐答案

Bleh,我有一个部分解决方案。我意识到我必须在状态结构上设置dwLength字段。这样我就可以获得当前的内存使用量。


$
仍然喜欢为任何失败的分配获得回调的方法,特别是在系统变得足够低以开始警告用户之前得到通知。那里有什么想法吗?
Bleh, I have a partial solution. I realized that I have to set the dwLength field on the status struct. So that allows me to get the current memory usage.

Would still love a way to get a callback for any failing allocation, and especially to be notified before the system gets low enough to start warning the user. Any ideas there?


这篇关于获得自由RAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆