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 500k Run, taskmgr.exe MsgBox, Remember current memory usage then compare. EmptyMem() Sleep, 5000 Exitapp 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) } 以下是用于减小PhotoShop占用内存的例子: Run, "C:/Program Files/Adobe/Adobe Photoshop CS3/Photoshop.exe",,,PID ;save PID here WinWait, ahk_class Photoshop ;wait for window existstence Sleep, 10000 ;photoshop's startup loading must be completed before apply it EmptyMem(PID) ;put photoshop's PID here as saved in first line Exitapp 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) }
减小应用程序占用内存的另一种方法(AHK脚本)
最新推荐文章于 2024-03-28 16:03:17 发布