减小应用程序占用内存的另一种方法(AHK脚本)

来源:互联网 发布:汉邦高科软件下载 编辑:程序博客网 时间:2024/05/01 02:07
2008-11-07 09:53参考AHK官方论坛:http://www.autohotkey.com/forum/topic32876.html&highlight=mem+usage derRaphael写了一个函数,用来释指定PID(进程)的内存,如果省略PID,则释放脚本本身的内存。在脚本开头部分及从前台转入后台时,调用一次该函数,可以将AHK占用内存从约5000k降低到约500k,效果非常明显。这简直就是魔术师所为,以下是这个函数:EmptyMem(PID="AHK Rocks"){ pid:=(pid="AHK Rocks") ? DllCall("GetCurrentProcessId") : pid h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid) DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1) DllCall("CloseHandle", "Int", h)}以下是用于对比测试的应用脚本:;This example will reduce mem usage from around 5,000k to 500kRun, taskmgr.exeMsgBox, Remember current memory usage then compare.EmptyMem()Sleep, 5000ExitappEmptyMem(PID="AHK Rocks"){pid:=(pid="AHK Rocks") ? DllCall("GetCurrentProcessId") : pidh:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)DllCall("CloseHandle", "Int", h)}以下是用于减小PhotoShop占用内存的例子:Run, "C:/Program Files/Adobe/Adobe Photoshop CS3/Photoshop.exe",,,PID ;save PID hereWinWait, ahk_class Photoshop ;wait for window existstenceSleep, 10000 ;photoshop's startup loading must be completed before apply itEmptyMem(PID) ;put photoshop's PID here as saved in first lineExitappEmptyMem(PID="AHK Rocks"){pid:=(pid="AHK Rocks") ? DllCall("GetCurrentProcessId") : pidh:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)DllCall("CloseHandle", "Int", h)}