制作内存密集型后台申请表]友好" [英] Making a memory intensive background application "friendly"

查看:162
本文介绍了制作内存密集型后台申请表]友好"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有定期需要处理大数据块与计算平凡算法的应用程序。原来我也可以prevent拖慢系统从硬盘驱动器通过保持在内存中缓存数据块访问。该应用程序是一个低优先级的应用程序,这样我的工作,以尽量减少其全线系统的影响,这意味着使用额外的内存(如果有),以减少CPU和硬盘驱动器上的负载。缓存的数据字节的只是64MB的块,并把它们的更多的我在内存中的开销少程序将对驱动器。

I have an application that periodically needs to process large blocks of data with a computationally trivial algorithm. It turns out I can also prevent slowing down the system from hard drive accesses by keeping the blocks of data in a memory cache. The application is a low-priority application so I'm working to minimize its impact on the system across the board, which means using extra memory (when available) to reduce the load on the CPU and hard drives. The cached data is just 64MB blocks of bytes, and the more of them I have in memory the less overhead the program will have on the drives.

我需要做的是转储内存缓存只要系统上的任何其他应用程序需要更多的物理内存比可用,而这样做的速度不够快,用户从来没有感觉系统变慢,由于高内存需求。

What I need to do is dump the in-memory cache whenever any other application on the system needs more physical memory than is available, and do so fast enough that the user never feels the system slowing down due to high memory demands.

我在如何做到这一点的.NET应用程序来完成特别感兴趣。

I'm particularly interested in how this would be accomplished in a .NET application.

推荐答案

一种选择是使用ASP.NET缓存,它可清除响应低内存的项目。虽然微软附加一个很大的警告,它只是一个ASP.NET应用程序中测试过,没有什么可以阻止你在任何应用程序访问 HttpRuntime.Cache ,并在实践中它一直当我这样做了。

One option would be to use the ASP.NET Cache, which scavenges items in response to low memory. While Microsoft attaches a big warning that it is only tested within an ASP.NET application, there's nothing to stop you accessing HttpRuntime.Cache in any application, and in practice it has worked when I've done so.

如果那种感觉肮脏的和错误(或只是没有做完全是你的需要),我们至少可以得出从ASP.NET如何知道要清除高速缓存中的灵感。它定期调用内核的 GlobalMemoryStatusEx 找出可用内存。具体而言,在 dwMemoryLoad 的返回的结构的属性是总存储器中使用的百分比。默认情况下,ASP.NET认为内存被耗尽时,这个达到90%以上。

If that feels dirty and wrong (or just doesn't do quite what you need), we can at least draw inspiration from how ASP.NET knows to scavenge the cache. It periodically calls the kernel's GlobalMemoryStatusEx to find out the memory available. Specifically, the dwMemoryLoad property of the returned structure is the percentage of total memory in use. By default, ASP.NET considers memory to be running out when this reaches 90%.

这里也有一些例子code自己调用这个函数这里

There's some example code to call this yourself here.

这篇关于制作内存密集型后台申请表]友好"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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