PDA

View Full Version : Memory cleaner for Windows 98/ME



Petr Schreiber
17-09-2007, 19:57
Hi,

I am not sure, maybe I posted this before, but today I had to use it again :)

In older Windows, the memory becomes more and more messy, more programs you run. Even if you just open/close one program multiple times, your system memory will show to be more and more occupied.

Sometimes. Mostly in case some programs do not release their resources correctly.

My brother was unhappy he cannot run his game because it says he has not enough RAM ( box: WinME, 512MB RAM ).
Using following script it is possible to make memory clean again. It seems to me that on older Win memory becomes fragmented a lot, and then it makes impression it is full. Or something like that :)

Solution is to try to allocate huge STRING. This will force system to defragment RAM. When program ends, memory "tunnel" harvested by script is free for use.



'=============================================================================
'= Memory defragmenter for Windows 98/ME =
'=============================================================================

TYPE MEMORYSTATUS
dwLength AS DWORD
dwMemoryLoad AS DWORD
dwTotalPhys AS DWORD
dwAvailPhys AS DWORD
dwTotalPageFile AS DWORD
dwAvailPageFile AS DWORD
dwTotalVirtual AS DWORD
dwAvailVirtual AS DWORD
END TYPE

DECLARE function GlobalMemoryStatus LIB "KERNEL32.DLL" ALIAS "GlobalMemoryStatus" (lpBuffer AS MEMORYSTATUS) as long

dim lpBuffer AS MEMORYSTATUS
GlobalMemoryStatus (lpBuffer) ' -- retrieves current status of memory
local freeMem as dword = val( _
inputbox$("How many MB of memory you want to have free ?"+$CRLF+"Specify number up to"+STR$(int(lpBuffer.dwTotalPhys/1024/1024)), _
"Enter memory amount", _
FORMAT$(int(lpBuffer.dwTotalPhys/1024/1024/2) )) _
)

if freeMem <= 0 then stop

if freeMem > lpBuffer.dwTotalPhys/1024/1024 then
freeMem = lpBuffer.dwTotalPhys
else
freeMem = freeMem * 1024 * 1024
end if

msgbox 0, "Program is about to defragment your physical memory by allocating "+format$( freeMem, "#,")+" bytes..."

dim DefragString as string * freeMem

msgbox 0, "Defragmentation finished"


So before running the game Windows ME reported free RAM as 256 MB, after running this script suddenly over 380 ;)
I recommend to run script multiple times, each time "eating" about 100-200 MB.

I think this trick works because thinBASIC strings are OLE ones, so they are really trying to fit best in memory of their mother Windows :)


Bye,
Petr

kryton9
18-09-2007, 03:23
That is incredible Petr, real thinking outside of the box for sure!

ErosOlmi
18-09-2007, 11:55
Petr,

the trick under Win98 seems working fine. I tested under an emulated Win98 with 256Mb total mem and 180Mb free.
After executing the script, free mem went to 210Mb

I suggest to use Petr script in conjunction with another script Petr did some time ago that is attached to this post.
Leave Memory2.tBasic running, than execute mem cleaner and you will see.

Ciao
Eros

PS: only under Win9x or WinME