Skip to content

Commit e490d16

Browse files
author
Victor Santiago Martinez Picardo
committed
RAM Optimizer article.
Signed-off-by: Victor Santiago Martinez Picardo <vmartinez@efor.es>
1 parent 4f8acaf commit e490d16

File tree

6 files changed

+137
-8
lines changed

6 files changed

+137
-8
lines changed

pills/ram_optimizer.html

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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>

static/data/pills.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,38 @@
3535
"title": "Wireshark <b>VNC capture</b>",
3636
"url": "",
3737
"page": "pills/wireshark_vnc_capture.html"
38+
},
39+
{
40+
"badges": [
41+
{
42+
"color": "badge-success",
43+
"name": "Automation"
44+
},
45+
{
46+
"color": "badge-info",
47+
"name": "Windows"
48+
},
49+
{
50+
"color": "badge-dark",
51+
"name": "AHK"
52+
}
53+
],
54+
"date": "2024/07/25",
55+
"description": "Free up <b>unused cache RAM</b> from Windows's Processes",
56+
"id": 1,
57+
"img": "static/img/pills/ram_optimizer/article.png",
58+
"ribbon": {
59+
"color": "",
60+
"name": ""
61+
},
62+
"tags": [
63+
"automation",
64+
"ahk",
65+
"memory",
66+
"windows"
67+
],
68+
"title": "<b>RAM Optimizer</b>",
69+
"url": "",
70+
"page": "pills/ram_optimizer.html"
3871
}
3972
]
62.5 KB
Loading
38.7 KB
Loading
6.2 KB
Loading

upcoming_content.html

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ <h1 id="pending">Pending</h1>
9696
<li>One Click VNC</li>
9797
<li>Minecraft Server Desktop Widget</li>
9898
<li>AutoHotkey Messenger</li>
99-
<li>RAM Optimizer</li>
10099
<li>Piou Piou Multiplayer Card Game (Custom Game Engine)</li>
101100
</ul>
102101
<div class="cl-preview-section">
@@ -110,13 +109,19 @@ <h2 id="done">Done:</h2>
110109
<div class="cl-preview-section">
111110
<h2 id="discarded">Discarded:</h2>
112111
</div>
113-
<ul>
114-
<li>Ontop replica</li>
115-
<li>Pokemon Twitch Bot Pokeballs (not done)</li>
116-
<li>OCR</li>
117-
<li>HTOP, NTOP, BTOP</li>
118-
<li>Metroid Prime Hunters Online Tool</li>
119-
</ul>
112+
<ul>
113+
<li>Ontop replica</li>
114+
<li>Pokemon Twitch Bot Pokeballs (not done)</li>
115+
<li>OCR</li>
116+
<li>HTOP, NTOP, BTOP</li>
117+
<li>Metroid Prime Hunters Online Tool</li>
118+
</ul>
119+
<div>
120+
<h2>In Progress:</h2>
121+
</div>
122+
<ul>
123+
<li>RAM Optimizer</li>
124+
</ul>
120125
</div>
121126
</div>
122127
</div>

0 commit comments

Comments
 (0)