函数与方程有啥区别:最小化后释放内存

来源:百度文库 编辑:中财网 时间:2024/04/29 01:43:04

最小化后释放内存

在几年前用VB编程的时候就发现,用无边框的窗体最小化后内存会大大减少,后来试了其他样式的窗体结果也是这样,在VC中也同样是这样。于是查了查百度才知道了一个API :SetProcessWorkingSetSize

 

我的百度博客: http://hi.baidu.com/wscdd

 

MSDN中如下介绍此API  翻译的不好请见谅

======================================================================

The SetProcessWorkingSetSize function sets the minimum and maximum working set sizes for the specified process.

The working set of a process is the set of memory pages currently visible to the process in physical RAM memory. These pages are resident and available for an application to use without triggering a page fault. The size of the working set of a process is specified in bytes. The minimum and maximum working set sizes affect the virtual memory paging behavior of a process.

作用就是设置一个进程在当前物理内存中的可视内存页。这些页面会常驻并被应用程序所使用而不触发错误。该工作进程指定了一个特别的字节。其最大最小的值将影响进程虚拟内存页的行为。

==========================================

根据这个API 我们可以在窗体初始化的时候调用该函数来“释放”我们的物理内存。

SetProcessWorkingSetSize(::GetCurrentProcess(),-1,-1);

这样,程序的可见物理内存就大大减少了。 如果你们觉得不想用这个API的话 可以在窗体显示的时候 ShowWindow(SW_MINIMIZE)最小化显示,然后再ShowWindow(SW_NORMAL) 也可以达到这个效果。

 

作此笔记仅供参考。Thanks.

This is CDD, or you can call me Jonathan.