There are a small trick to defrag the RAM with a simple command.
This tip is to keep the physical RAM defragmented time to time.
I just use it in the Start menu->Start folder, and the results are nice, over all if the computer is turned-on during more than 48 hours without restart system neither switch-off it.
It seems to work for XP and older, and old PC (pentium 4 or olders).
Code: Select all
; What this code does is it allocates large chunk of memory in RAM and If allocated size is larger than available free RAM then this forces OS to swap some less used
; RAM pages to disk (pagefile) to make space for newly allocated memory.
; This code (vbe script) does nothing else and it ends immediately so this newly allocated memory is also immediately marked as free RAM.
; But swapped memory pages from pagefile are not loaded back to RAM immediately now that there is free space for them again, they are loaded back only when these apps
; which allocated these swapped out pages try to access them again in the future.
; And only then, in the future, "RAM defragmentation" happens because OS tries To put pages from pagefile to RAM in sequential order as much as possible.
; 100% defragmentation is not guaranteed and practically impossible.
; It is also theoretically possible to sometimes end up with more fragmented RAM by running this code.
;
; Whole explanation above is obviously simplified and there is a lot more going on "under the hood":
; https://msdn.microsoft.com/en-us/library/ms810627.aspx
; https://en.wikipedia.org/wiki/Paging
ram0.MEMORYSTATUSEX:mem.l:minutos.u=9
ram0\dwLength=SizeOf(MEMORYSTATUSEX)
GlobalMemoryStatusEx_(@ram0)
ram.i=ram0\ullTotalPhys/1024/1024
mem=ram*0.6
Repeat
Delay(minutos*60000)
OpenFile(0,"ram.vbe",#PB_Ascii):;TruncateFile(0)
WriteStringN(0,"Mystring=("+Str(mem)+"000000)",#PB_Ascii)
CloseFile(0)
If RunProgram("ram.vbe","","",#PB_Program_Wait):DeleteFile("ram.vbe")
Else:Beep_(700,7000)
EndIf
ForEver