|
![]() | 作者: zhoen889 [zhoen889]
![]() |
登录 |
应用环境:WinXp,Win2K 程序原来运行占用11M内存,用动态创建窗口的方法只能减少不到10m,应用此方法后内存占用只有600K左右。 具体方法是: 把下面的过程放到一个Timer中,每隔一段时间执行一次,如5秒。 { ************** * Clear Memory ************** } procedure ClearMemory; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); Application.ProcessMessages; end; end; [此贴被 见晨晓风(zhoen889) 在 10月26日13时37分 编辑过] [此贴被 见晨晓风(zhoen889) 在 10月26日13时37分 编辑过] |
地主 发表时间: 05-10-26 13:34 |
![]() | 回复: jhkdiy [jhkdiy] ![]() |
登录 |
不错啊,我用Win32Asm试了,原来占用 1423K 内存。用该方法后只占用 174k 。呵呵。我再补充一下吧,关键是API函数SetProcessWorkingSetSize(),以下是MSDN的说明: 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. BOOL SetProcessWorkingSetSize( HANDLE hProcess, // handle to process SIZE_T dwMinimumWorkingSetSize, // minimum working set size SIZE_T dwMaximumWorkingSetSize // maximum working set size ); If both dwMinimumWorkingSetSize and dwMaximumWorkingSetSize have the value -1, the function temporarily trims the working set of the specified process to zero. This essentially swaps the process out of physical RAM memory. [此贴被 jhkdiy(jhkdiy) 在 10月26日22时46分 编辑过] [此贴被 jhkdiy(jhkdiy) 在 10月26日22时47分 编辑过] |
B1层 发表时间: 05-10-26 22:40 |
|
20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon
粤ICP备05087286号