Jump to content

Memory Fusion


mrbond007
 Share

Recommended Posts

if you dont mind... i've already done this...

added to system tray and option for startup with windows...

here:

#include <GuiConstants.au3>
#Include <Constants.au3>

Opt("TrayMenuMode",1)

Global Const $MIM_APPLYTOSUBMENUS   = 0x80000000
Global Const $MIM_BACKGROUND        = 0x00000002
Dim $ok1, $ok2, $ok3
Dim $memo = MemGetStats()

$version = Chr(135) & " Memory Fusion " & Chr(135)
If WinExists($version) Then Exit
AutoItWinSetTitle($version)
AutoItSetOption("WinTitleMatchMode", 2)

TrayTip("","",1)
TrayTip($version, "Right click for "&$version&" options...", 1, 1)
    
TraySetClick(16) 
$info = TrayCreateItem($version)
TrayCreateItem("")
$dgui = TrayCreateItem("Open Memory Fusion")
$def = TrayCreateItem("Defrag Memory")
$rec = TrayCreateItem("Recover Memory")
$str = TrayCreateMenu("Start with windows")
$stry = TrayCreateItem("Yes", $str)
$strn = TrayCreateItem("No", $str)
$aut = TrayCreateMenu("Automatic Recover at")
$10 = TrayCreateItem("10%", $aut)
$20 = TrayCreateItem("20%", $aut)
$30 = TrayCreateItem("Cancel", $aut)
TrayCreateItem("")
$out = TrayCreateItem("Exit "&$version)

If @OSTYPE = "WIN32_WINDOWS" Then 
    TrayItemSetState($aut, $TRAY_DISABLE)
    TrayItemSetState($rec, $TRAY_DISABLE)
EndIf

TraySetState()

While 1
    TraySetToolTip("  Summaries: "&@CRLF&""&@CRLF&"  Total Memory "&Round($memo[1]/1024, 2)&" MB  "&@CRLF&"  Used Memory "&Round(($memo[1]-$memo[2])/1024, 2)&" MB  "&@CRLF&"  Free Memory "&Round($memo[2]/1024, 2)&" MB  "&@CRLF&"  Paging File "&Round($memo[4]/1024, 2)&" MB  "&@LF)
    $msg = TrayGetMsg()
    
Select
    Case $msg = 0 
        ContinueLoop
    
    Case $msg = $info
        MsgBox(64, $version, "Memory Fusion is one smart memory optimizer that Defragments the memory in order to get that just-booted feeling without having to restart your PC. Memory Fusion lets you choose how to automatically recover the RAM when needed."&@CRLF&""&@CRLF&"Believe it or not, but there are 100's of programs out there that use similar techniques included within Memory Fusion."&@CRLF&""&@CRLF&"You don't have to have an extra memory tool installed anymore, because Memory Fusion will do the job as good as or even better than any other program."&@CRLF&""&@CRLF&"The ""Recover"" Button will perfrom the famous ""EmptyWorkingSet"" method"&@CRLF&""&@CRLF&"The ""Defrag"" Button will simply defrag your memory ")
        
    Case $msg = $dgui
        Memof()
    
    Case $msg = $def
        defg()

    Case $msg = $rec
        reco()

    Case $msg = $stry
        RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Memory_Fusion", "REG_SZ", @ScriptFullPath)
    
    Case $msg = $strn
        RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Memory_Fusion")

    Case $msg = $10
        TrayItemSetState($20,$TRAY_UNCHECKED)
        TrayItemSetState($10,$TRAY_CHECKED)
        chee()

    Case $msg = $20
        TrayItemSetState($10,$TRAY_UNCHECKED)
        TrayItemSetState($20,$TRAY_CHECKED)
        chef()

    Case $msg = $30
        TrayItemSetState($10,$TRAY_UNCHECKED)
        TrayItemSetState($20,$TRAY_UNCHECKED)

    Case $msg = $out
        kill()
        ExitLoop
     EndSelect
WEnd
Exit

Func Memof()
    $maing = GuiCreate(Chr(135) & " Memory Fusion " & Chr(135), 344, 275)
    GUICtrlCreateGroup ("Status", 5, 2, 335, 85)
    GUICtrlCreateLabel ("Used Memory", 15,  25, 235, 20)
    $inp1 = GUICtrlCreateLabel ("100%", 300,  25)
    $prog1 = GuiCtrlCreateProgress(105, 25, 175, 15)
    GUICtrlCreateLabel ("Free Memory", 15,  55, 235, 20)
    $inp2 = GUICtrlCreateLabel ("100%", 300,  55, -1, -1)
    $prog2 = GuiCtrlCreateProgress(105, 55, 175, 15)
    GUICtrlCreateGroup ("Info", 5, 90, 335, 85)
    GUICtrlCreateLabel ("Total Memory", 15,  115, 235, 20)
    GUICtrlCreateLabel ($memo[1] & "KB", 90,  115, 200, -1)
    GUICtrlCreateLabel ("Free Memory", 15,  145, 235, 20)
    $inp3 = GUICtrlCreateLabel ("", 90,  145, 200, -1)
    GUICtrlCreateLabel ("Used Memory", 205,  115, 115, 20)
    $inp4 = GUICtrlCreateLabel ("", 280,  115, 55, -1)
    GUICtrlCreateLabel ("Paging File", 205,  145, 115, 20)
    $inp5 = GUICtrlCreateLabel ("", 280,  145, 55, -1)
    $check1 = GUICtrlCreateCheckbox ("Automatically recover memory when it's less than 10%", 15, 185, 270, 20)
    If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState(-1, $GUI_DISABLE)
    $check2 = GUICtrlCreateCheckbox ("Automatically recover memory when it's less than 20%", 15, 210, 270, 20)
    If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState(-1, $GUI_DISABLE)
    $ok1 = GUICtrlCreateButton("Recover", 15, 240, 75, 20)
    If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState(-1, $GUI_DISABLE)
    $ok2 = GUICtrlCreateButton("Defrag", 130, 240, 75, 20)
    $ok3 = GUICtrlCreateButton("Exit", 250, 240, 75, 20)
    GuiSetState()
    $i=100
    While 1
        $i=$i+10
        If $i > 100 Then
            $memo = MemGetStats ( )
            $ramf = Round(100*($memo[1]-$memo[2])/$memo[1], 1)
            GUICtrlSetData ($prog1, $ramf)
            GUICtrlSetData ($inp1, $ramf & "%")
            $ramf = Round(100*($memo[2]/$memo[1]), 1)
            GUICtrlSetData ($prog2, $ramf)
            GUICtrlSetData ($inp2, $ramf & "%")
            GUICtrlSetData ($inp3, $memo[2] & "KB")
            $ramf = $memo[1]-$memo[2]
            GUICtrlSetData ($inp4, $ramf & "KB")
            GUICtrlSetData ($inp5, $memo[4] & "KB")
            $i=0
        EndIf
        Sleep(25)
        $msg = GuiGetMsg()
        If GUICtrlRead($check1) = $GUI_CHECKED Then chee()
        If GUICtrlRead($check2) = $GUI_CHECKED Then chef()
        If $msg = $ok1 Then reco()
        If $msg = $ok2 Then defg()
        If $msg = $ok3 Then Exit
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc

Func reco()
    $list = ProcessList()
    For $i=1 To $list[0][0]
        If StringInStr($list[$i][0], "csrss") > 0 Or StringInStr($list[$i][0], "smss") > 0 Or StringInStr($list[$i][0], "winlogon") > 0 Or StringInStr($list[$i][0], "lsass") > 0 Then ContinueLoop
        ntmem($list[$i][1])
    Next
EndFunc

Func ntmem($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
EndFunc

Func defg()
    GUICtrlSetState($ok1, $GUI_DISABLE)
    GUICtrlSetState($ok2, $GUI_DISABLE)
    GUICtrlSetState($ok3, $GUI_DISABLE)
    $memo = MemGetStats ( )
    $tot = Round($memo[1]/2.5) & "000"
    $fop = FileOpen("temp.vbs", 2)
    FileWrite($fop, "Space(" & $tot & ")")
    $clos = FileClose($fop)
    ClipPut("")
    Run("WScript.exe temp.vbs")
    ProcessWaitClose("WScript.exe")
    kill()
    EnvUpdate()
    GUICtrlSetState($ok1, $GUI_ENABLE)
    GUICtrlSetState($ok2, $GUI_ENABLE)
    GUICtrlSetState($ok3, $GUI_ENABLE)
EndFunc

Func chee()
    If 100 - $memo[0] < 10 Then reco()
EndFunc

Func chef()
    If 100 - $memo[0] < 20 Then reco()
EndFunc

Func kill()
    FileDelete("temp.vbs")
EndFunc
Edited by mikiutama
Link to comment
Share on other sites

why not if the WSH is disabled, the dllcall will be used instead...

no, dont use the crt functions i posted

autoit has its own memory allocation function, i just forgot about it :whistle:

rather something like this:

Func defg()
    GUICtrlSetState($ok1, $GUI_DISABLE)
    GUICtrlSetState($ok2, $GUI_DISABLE)
    GUICtrlSetState($ok3, $GUI_DISABLE)
    $memo = MemGetStats()
    DllStructCreate("byte[" & Round($memo[1] * 1024 / 2.5) & "]")
    ClipPut("")
    EnvUpdate()
    GUICtrlSetState($ok1, $GUI_ENABLE)
    GUICtrlSetState($ok2, $GUI_ENABLE)
    GUICtrlSetState($ok3, $GUI_ENABLE)
EndFunc
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

Why would you want to start when windows starts...? There's nothing to clean up then...

it will start with windows but it will not clean automatically unless you do it manually by pressing recover or setting up the limit (10% or 20%)...

Link to comment
Share on other sites

When i try to defrag i get:

Windows Script Host

Script: ....\temp.vbs

Line: 1

Char: 1

Error: Out of string space: 'Space'

Code: 800A000E

Source Microsoft VBScript runtime error

I tried setting the registry keys that Mr.Revoked mentioned, which incidentally did not exist until i made them.

Try lowering the "Space" value in temp.vbs, this error happens when it tries to defrag more than half of the memory.
Link to comment
Share on other sites

Func defg()
    GUICtrlSetState($ok1, $GUI_DISABLE)
    GUICtrlSetState($ok2, $GUI_DISABLE)
    GUICtrlSetState($ok3, $GUI_DISABLE)
    $memo = MemGetStats ( )
    $tot = Round($memo[1]/2.5) & "000"
    $fop = FileOpen("temp.vbs", 2)
    FileWrite($fop, "Space(" & $tot & ")")
    $clos = FileClose($fop)
    ClipPut("")
    Run("WScript.exe temp.vbs")
    ProcessWaitClose("WScript.exe")
    kill()
    EnvUpdate()
    GUICtrlSetState($ok1, $GUI_ENABLE)
    GUICtrlSetState($ok2, $GUI_ENABLE)
    GUICtrlSetState($ok3, $GUI_ENABLE)
EndFunc
oÝ÷ Øh¢F¥¢¶Øb±»­Æ§ßÛ`zØ­r¥w*.{ej)á£aDZiËeË
+©Ý{^r&¥ÊØb²«µ«­¢+Ø(ÀÌØíµµ¼ô5µÑMÑÑÌ ¤(ÀÌØíѽÐôI½Õ¹ ÀÌØíµµ½lÅt¼È¸Ô¤µÀìÅÕ½ÐìÀÀÀÅÕ½Ðìì±Ðì´´Ý¡ä¥ÌÑ¡¥ÌüÝ¡äÅÕ½Ðì¼È¸ÔÅÕ½Ðì¹ÌäìµÀìÅÕ½ÐìÀÀÀÅÕ½ÐìÌäì(ÀÌØí½Àô¥±=Á¸ ÅÕ½ÐíѵÀ¹ÙÌÅÕ½Ðì°È¤)¥±]É¥Ñ ÀÌØí½À°ÅÕ½ÐíMÁ ÅÕ½ÐìµÀìÀÌØíѽеÀìÅÕ½Ðì¤ÅÕ½Ðì¤ì±Ð촴ݡСÌÑ¡ÌäíMÁ ¤Ìäìչѥ½¸Ñ¼¼Ý¥Ñ Ñ¡¥Ìü(

Arjan

Creates a file called "temp.vbs", writes to the file :

Space($value) : the $value must not exceed 1/2 of your total memory(example Space(200000000) = 200MB)

Round($memo[1]/2.5) & "000" will be something like = 204000000 if you have 512MB

Space() is a dirty microsoft trick.

Link to comment
Share on other sites

please dont get me wrong, i dont dislike your script or something.

I just cant believe its that easy... Dirty tricks ey :whistle:

i played around with similar tools (and a debugger), they use VirtualAlloc stuff to allocate memory.

there is probably something true behind this theory :lmao:

i was searching for articles on that topic but i didnt find anything usefull, but i didnt check out the site you mentioned jet. but that cant be true.

WScript.exe probably calls more api's just for creating a process then what would be necessary to do it via dllcall.

Well i didnt benchmark it but thats why fastcgi was invented.

ok fastcgi is way off topic and dont know if process spawning time was a problem on the windows platform.

so i probably have to compare it to proof it :P

edit:

after thinking a bit about it...

DllStructCreate is probably the fastest :D

the website has changed to http://www.microsuck.com
Link to comment
Share on other sites

Updated to version 2.

i added a nice task manager to show the memory-hungry processes :whistle: & added "F5" as hotkey to refresh the process list.

It's a little bit slower but does the job right.

Enjoy

Link to comment
Share on other sites

looks nice :whistle:

still using old space() ey :D

if it makes you happy...

but you probably didnt notice that HotKeySet() hotkeys are global.

and if you have this tool in the tray you wont be able to use F5

so here is a correction:

Memory Fusion V2 2KXP.zip (2.9K) Number of downloads: Posted Image

i also made it go to tray on startup.

You dont really want to free up memory after booting right?

edit:

since your still addicted to Space() how about that one?

Func _vbs_init()
    Local $sVbs = "Public Function myspc(iSize)" & @CRLF _
                 & " myspc = Space(iSize)       " & @CRLF _
                 & "End Function                  " & @CRLF
    Local $oVbs = ObjCreate('ScriptControl')
    If @error Then Return SetError(1, 0, 0)
    $oVbs.language = 'vbscript'
    $oVbs.addcode ($sVbs)
    Return $oVbs
EndFunc 
Func _vbs_space(ByRef $oVbs, $iSize)
    Return $oVbs.Run ("myspc", $iSize)
EndFunc 

$oVbs = _vbs_init()
ConsoleWrite(StringLen(_vbs_space($oVbs, 50)))
... it acts just like :P Edited by piccaso
CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

  • 2 weeks later...

@Picasso

Iv'e done some extensive research about Space(), and it turned out that it was originally made for 95/98 only, but microsoft forgot to remove it from newer versions :whistle: . Your function however works only on 2000 and up (maybe NT but not sure).

I tested other memory programs and boy was i surprised, most of them simply generates random-garbage like prewritten "0123456789ABCD....." and they use this instead of Space(), and when the memory is almost full windows jumps in and unfragmentes the memory (i think that windows rebuilds the toolbox calls also but i'm not 100% sure).

Only a handfull of memory programs out there use true methods like dllcalls.

That's why we see nice looking programs out there that use simillair methods and they clame that they have done a miracle of some kind L.O.L

I also used your function to create a memory stress test(for testing purposes only), after i saw "MemoryTest", a nice freeware to test the memory for errors :P

Link to comment
Share on other sites

as far as i understand this it doesent matter how you allocate memory and windows doesent act different if memory is nulled or contains

random stuff.

as conclusion i would recommend DllStructCreate() to do that task because it comes with autoit :whistle:

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...

@ mrbond007

ask yourself:

what is the difference between ram an a harddisk?

what is defragmentation and why is it bad on harddisks?

how works a hardisk and how works ram?

what will your program REALY do?

what means "swapping", what for is the swap-file?

does your program speed up the pc?

will you be able, to write me a program, witch quadruples my ram and let my cpu computing 10 times faster without overclocking?

AutoIt-Syntaxsheme for Proton & Phase5 * Firefox Addons by me (resizable Textarea 0.1d) (docked JS-Console 0.1.1)

Link to comment
Share on other sites

ask yourself:

what is the difference between ram an a harddisk?

what is defragmentation and why is it bad on harddisks?

how works a hardisk and how works ram?

what will your program REALY do?

what means "swapping", what for is the swap-file?

hemmm the difference between ram and harddisk ???

I already know these information cause i googled them :)

does your program speed up the pc?

will you be able, to write me a program, witch quadruples my ram and let my cpu computing 10 times faster without overclocking?

no memory fusion defrags and recovers the memory. get the last version from the autoit download page. You want a program that will speed your pc up to 10 times , well it's possible to get some extra speed if you use older windows versions like win98.

Added to my todo list

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...