Last active
May 28, 2019 16:34
-
-
Save aviaryan/5309545 to your computer and use it in GitHub Desktop.
Reduce memory consumption of your Autohotkey scripts.
Works with all Ahk versions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
ScriptMem - Reduce Memory consumption of your AHK Script | |
by Avi Aryan | |
Thanks -- | |
HERESY - for EmptyMem function | |
just me - for GetScriptPID fucntion | |
Works with all AHK | |
USING ------ | |
Recommended to use at the end of Auto-Execute section. | |
AND | |
only at frequent intervals | |
WHY ?? | |
Any process tends to assume higher memory consumption than it actually needs. | |
So, after end of Auto-execute you are likely to have max. extra memory for the script | |
process. | |
*/ | |
ScriptMem() | |
{ | |
static PID | |
IfEqual,PID | |
{ | |
DHW := A_DetectHiddenWindows | |
TMM := A_TitleMatchMode | |
DetectHiddenWindows, On | |
SetTitleMatchMode, 2 | |
WinGet, PID, PID, \%a_ScriptName% - ahk_class AutoHotkey | |
DetectHiddenWindows, %DHW% | |
SetTitleMatchMode, %TMM% | |
} | |
h:=DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid) | |
DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1) | |
DllCall("CloseHandle", "Int", h) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks AviaryAn for great job!
Very usefull!