1+ < div >
2+ < div >
3+ < p >
4+ This is something I didn't plan to release due to the small complexity of the project, but we use it quite often at our workplace and I find it a very useful and interesting resource.
5+ < br >
6+ Sometimes < i > Microsoft SQL Server Management Studio</ i > hangs due to RAM constraints, this < b > leverages that quite well</ b > .
7+ < br > < br >
8+ < div class ="row ">
9+ < div class ="col-md-3 col-sm-6 col-12 ">
10+ < a href ="https://github.com/elModo7/RAM_Optimizer " target ="_blank ">
11+ < div class ="info-box bg-gradient-dark shadow-lg ">
12+ < span class ="info-box-icon "> < i class ="fab fa-github "> </ i > </ span >
13+ < div class ="info-box-content ">
14+ < span class ="info-box-number "> Project's GitHub</ span >
15+ < span class ="progress-description ">
16+ RAM Optimizer
17+ </ span >
18+ </ div >
19+ </ div >
20+ </ a >
21+ </ div >
22+ </ div >
23+ < br >
24+ < img class ="shadow-lg article-inner-image " src ="static/img/pills/ram_optimizer/ram_optimizer.png "> </ img >
25+ < img class ="shadow-lg article-inner-image " src ="static/img/pills/ram_optimizer/ram_optimizer.gif "> </ img >
26+ < br > < br >
27+ < h4 > Libraries used:</ h4 >
28+ < br > < b > XGraph</ b > library by SKAN (Suresh Kumar A N)
29+ < br > < b > MemoryLoad</ b > by < a class ="link " href ="https://github.com/jNizM " target ="_blank "> jNizM</ a >
30+ < br > < b > EmptyMem</ b > by Heresy
31+ < br > < b > FreeMemory</ b > by SKAN (Suresh Kumar A N)
32+ </ p >
33+ < br >
34+ < h3 > 💻 Explaining the main 3 functions:</ h3 >
35+ < pre class ="col-md-12 "> < code class ="language-autohotkey ">
36+ ; Function to get the current memory load percentage
37+ MemoryLoad()
38+ {
39+ ; Define a static variable MEMORYSTATUSEX and initialize it with the size of the structure.
40+ ; 'init' is a dummy variable to ensure the NumPut operation executes only once.
41+ static MEMORYSTATUSEX, init := NumPut(VarSetCapacity(MEMORYSTATUSEX, 64, 0), MEMORYSTATUSEX, "uint")
42+
43+ ; Call the Windows API function 'GlobalMemoryStatusEx' to fill the MEMORYSTATUSEX structure.
44+ if !(DllCall("GlobalMemoryStatusEx", "ptr", &MEMORYSTATUSEX))
45+ ; If the call fails, throw an exception with the last error code.
46+ throw Exception("Call to GlobalMemoryStatusEx failed: " A_LastError, -1)
47+
48+ ; Retrieve and return the memory load percentage from the MEMORYSTATUSEX structure.
49+ return NumGet(MEMORYSTATUSEX, 4, "UInt")
50+ }
51+
52+ ; Function to free up memory used by a specific process or the current process
53+ EmptyMem(PID="AHK Rocks"){
54+ ; If PID is "AHK Rocks" (default), get the current process ID; otherwise, use the provided PID.
55+ pid := (pid="AHK Rocks") ? DllCall("GetCurrentProcessId") : pid
56+
57+ ; Open the process with specific access rights and get a handle to it.
58+ h := DllCall("OpenProcess", "UInt", 0x001F0FFF, "Int", 0, "Int", pid)
59+
60+ ; Set the process's working set size to minimum (-1), effectively asking Windows to trim it.
61+ DllCall("SetProcessWorkingSetSize", "UInt", h, "Int", -1, "Int", -1)
62+
63+ ; Close the handle to the process to free resources.
64+ DllCall("CloseHandle", "Int", h)
65+ }
66+
67+ ; Function to free up memory used by all running processes
68+ FreeMemory()
69+ {
70+ ; Iterate over all running processes using Windows Management Instrumentation (WMI)
71+ for objItem in ComObjGet("winmgmts:").ExecQuery("SELECT * FROM Win32_Process") {
72+ try {
73+ ; Open each process with specific access rights and get a handle to it.
74+ hProcess := DllCall("OpenProcess", "uint", 0x001F0FFF, "int", 0, "uint", objItem.ProcessID, "ptr")
75+
76+ ; Set the process's working set size to minimum (-1) to free up memory.
77+ DllCall("SetProcessWorkingSetSize", "ptr", hProcess, "uptr", -1, "uptr", -1)
78+
79+ ; Call 'EmptyWorkingSet' to further trim the process's memory usage.
80+ DllCall("psapi.dll\EmptyWorkingSet", "ptr", hProcess)
81+
82+ ; Close the handle to the process.
83+ DllCall("CloseHandle", "ptr", hProcess)
84+ }
85+ }
86+ ; Finally, call 'EmptyWorkingSet' on the current process (-1) to clean up its memory.
87+ return DllCall("psapi.dll\EmptyWorkingSet", "ptr", -1)
88+ }
89+ </ code > </ pre >
90+ </ div >
91+ </ div >
0 commit comments