简体   繁体   English

Windows CE中的内存不足通知

[英]Low memory notifications in Windows CE

Is there a way to get notifications when the available memory goes below a certain limit (user configurable)? 有可能在可用内存低于某个限制(用户可配置)时收到通知吗? I have looked into the WM_HIBERNATE event but it seems the limit for this event is not user configurable and is hard-coded (160KB??). 我查看了WM_HIBERNATE事件,但似乎此事件的限制不是用户可配置的,并且是硬编码的(160KB ??)。 The only way I can think of is to poll the OS periodically (every 5 seconds??) for available memory through GlobalMemoryStats() API and if the available memory goes below the user configured limit then raise an event to the user. 我能想到的唯一方法是通过GlobalMemoryStats()API定期轮询操作系统(每5秒钟一次)获取可用内存,如果可用内存低于用户配置的限制,则向用户发出一个事件。 Is there a better way? 有没有更好的办法?

This notification has to work on devices starting with Windows CE 5.0 & Windows Mobile 6.5 此通知必须适用于从Windows CE 5.0和Windows Mobile 6.5开始的设备

There's nothing inherent in the OS that's going to tell you that memory is below an arbitrary level, no. 操作系统中没有什么固有的东西可以告诉你内存低于任意级别,没有。 Either polling in your app or creating a service/driver that does it for you is probebly the best way. 您可以在应用程序中进行轮询或创建为您执行此操作的服务/驱动程序,这是最佳方式。 Which is "better" would depend on if only one process needs to know about the notification. 哪个“更好”取决于是否只有一个进程需要了解通知。

If thats your application that can drain memory, then you can implement some code to intercept such low memory situations before system will do it. 如果这是你的应用程序可以耗尽内存,那么你可以实现一些代码来拦截这种低内存情况,然后系统才会这样做。 Some hints: 一些提示:

  • override your new, malloc or any other function that allocates memory and check each time if allocation will drain your memory. 覆盖新的,malloc或任何其他分配内存的函数,并检查每次分配是否会耗尽内存。

  • if you are afraid you will slow down your app (and you should:)) then use some memory manager, like Dougs Lee malloc.c, you can modify is so each time it grabs another 64KB block from system memory you will check if system memory is not too low 如果你害怕你会减慢你的应用程序(你应该:))然后使用一些内存管理器,如Dougs Lee malloc.c,你可以修改是这样每次它从系统内存中抓取另一个64KB块你将检查是否系统记忆力不是太低

  • you can read from registry what are the low memory levels, you will find these entries under: HKLM\\System\\Hibernate for WCE and HKLM\\System\\OOM for WM. 你可以从注册表中读取什么是低内存级别,你会发现这些条目:WLC的HKLM \\ System \\ Hibernate和WM的HKLM \\ System \\ OOM。

http://msdn.microsoft.com/en-us/library/ms911907.aspx http://msdn.microsoft.com/en-us/library/ms911907.aspx

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

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