Jump to content

_ReduceMemory GUI


Hammerfist
 Share

Recommended Posts

<<<< _ReduceMemory GUI >>>>

UDF so called '_ReduceMemory UDF' can optimize any process at the computer.

So I wrote a small program that can reduce a RAM usage of any process excluding system processes. There are small stats:

NOKIA PC Suite v7 (PCSuite.exe): 31890kb -->> 1089kb

Explorer.exe: 19800kb -->> 2170kb

Here are the source:

#Region
#AutoIt3Wrapper_outfile=Reducer.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Description=RAM Usage Reducer
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/striponly
#EndRegion

Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_FOCUS = 256
Global Const $LVM_FIRST = 0x1000
Global Const $LVHT_ONITEMICON = 0x00000002
Global Const $LVHT_ONITEMLABEL = 0x00000004
Global Const $LVHT_ONITEMSTATEICON = 0x00000008
Global Const $LVHT_ONITEM = BitOR($LVHT_ONITEMICON, $LVHT_ONITEMLABEL, $LVHT_ONITEMSTATEICON)
Global Const $LVN_FIRST = -100
Global Const $WS_MINIMIZEBOX = 0x00020000
Global Const $WS_SYSMENU = 0x00080000
Global Const $WS_CAPTION = 0x00C00000
Global Const $WS_POPUP = 0x80000000
Global Const $GUI_SS_DEFAULT_GUI = BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)

Global $data[999], $pctrl[999]

_Main()

Func _ProcGet()

$P_list = ProcessList()

For $i = 1 to $P_List[0][0]
    $v1 = ProcessGetStats($p_list[$i][1], 0)
    If IsArray($v1) then
    $data[$i] = $p_list[$i][0] & "|" & $p_list[$i][1] & "|" & $v1[0]/1024 & " кб"
    Else
    $data[$i] = $p_list[$i][0] & "|" & $p_list[$i][1] & "|" & "<system>"
    EndIf
Next
$data[0] = $P_List[0][0]

For $i = 1 to $data[0]
    GUICtrlDelete($pctrl[$i])
Next

For $i = 1 to $data[0]
    $pctrl[$i] = GUICtrlCreateListViewItem($data[$i], $ListView1)
Next


EndFunc

Func _Main()

Local $pctrl[999]

$Form1 = GUICreate("_ReduceMemory GUI", 447, 438, 193, 125)
$Group1 = GUICtrlCreateGroup("Let's start!", 8, 4, 429, 425)
Global $ListView1 = GUICtrlCreateListView("Process name|PID|RAM|", 16, 24, 410, 358)
GUICtrlSendMsg(-1, 0x101E, 0, 230)
GUICtrlSendMsg(-1, 0x101E, 1, 50)
GUICtrlSendMsg(-1, 0x101E, 2, 90)
GUICtrlSendMsg(-1, 0x101E, 3, 1)
$Button1 = GUICtrlCreateButton("Optimize selected process", 22, 392, 200, 25, 0)
$Button2 = GUICtrlCreateButton("Refresh list", 228, 392, 200, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetBkColor(0xffffff)
GUISetState(@SW_SHOW)

_ReduceMemory(@AutoItPID)
_ProcGet()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $plist1 = GUICtrlRead($ListView1)
            $Pdata = GUICtrlRead($plist1)
            If $pdata <> "" and Not StringInStr($pdata, "<system>") then
            $Name = StringSplit($pdata, "|")
            $NameP = $Name[2]
            _ReduceMemory($namep)
            _ProcGet()
            EndIf
            GUICtrlSetState($plist1, $GUI_FOCUS)
        Case $Button2
            $plist1 = GUICtrlRead($ListView1)
            _ProcGet()
            GUICtrlSetState($plist1, $GUI_FOCUS)
    EndSwitch
WEnd

EndFunc

Func _ReduceMemory($i_PID)
    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

    Return $ai_Return[0]
EndFunc ;==>_ReduceMemory

Enjoy =))

Edited by Hammerfist
Link to comment
Share on other sites

Why would you want to reduce memory usage of explorer.exe for example?

Do you think that's needed? Do you think developers of explorer.exe (or almost any other app) forgot about that?

edit:

Nice gui. Refreshingly white.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

See here : http://msdn.microsoft.com/en-us/library/ms682606(VS.85).aspx

Note that EmptyWorkingSet has been moved to kernel32.dll in Windows 7 and above.

WBD

Link to comment
Share on other sites

I think MicroSoft doesn't care about reducing memory with their programs, I think that they try to use as much memory as they can with every program expecting you (the end user) to always have to newest computers running their software. Most updates they release do not work well on three to five year old computer. but that's just my thoughts.

Gnatwork Networks

Link to comment
Share on other sites

its not just that they forgot to release the memory but for the end user, it is preferrable to release the memory SPECIALLY EMPTYWORKINGSET which does give a bit of ram on every usage. but nevertheless, microsoft programs do take their own part of ram as much as needed in few moments (of course, same applies to most programs) and btw, it is very helpful with most programs specially stuff where the memory release is not explicitly done. because as far as i have understood windows may not try to occupy the space of unreleased objects / etc unless the space is required by other process!

Link to comment
Share on other sites

You should all know that this is not an optimizer but will in most cases make the programs run slower (however it will indeed temporarily free up ram).

I dont know how do you want to use it but I use this 'optimizer' to optimize 'background' applications such as PCSuite. They all need a very few RAM amount to work correctly.

Note that EmptyWorkingSet has been moved to kernel32.dll in Windows 7 and above.

WBD

All my progs are for WinXP because I haven't so powerful machine to work on Win7 and even Vista. I have no reason to work with Vista or Win7 tech documentation. Sorry =(

Edited by Hammerfist
Link to comment
Share on other sites

Why would you want to reduce memory usage of explorer.exe for example?

Do you think that's needed? Do you think developers of explorer.exe (or almost any other app) forgot about that?

1st: 'explorer.exe' is just an example.

2nd: if you change the current page in the 'explorer tree' you can see that RAM usage of 'explorer.exe' process grows up to the same 30MB.

3rd: even if developer of 'explorer' include that function as some cleanup function, it will only clean up non-released pages and they will soon be fill by 'fresh' data.

Link to comment
Share on other sites

1st: 'explorer.exe' is just an example.

2nd: if you change the current page in the 'explorer tree' you can see that RAM usage of 'explorer.exe' process grows up to the same 30MB.

3rd: even if developer of 'explorer' include that function as some cleanup function, it will only clean up non-released pages and they will soon be fill by 'fresh' data.

That's why I said for example.

I'm confident that RAM usage of that kind of processes is always as it should be. There are something called caching and that is done intentionally to improve performance, not to reduce it. Memory leak is always possible but extremely unlikely to happen with these apps. Even if it happens there is always some monitoring installed and correction is done.

EmptyWorkingSet function is particulary useful when recursion occurs, when you have large amount of assigned variables an you wanna deal with them fast on reentrance (I can demonstrate if you like).

So, EmptyWorkingSet on current process in some particular cases. Other than that - really no needed.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

EmptyWorkingSet function is particularly useful when recursion occurs, when you have large amount of assigned variables an you wanna deal with them fast on reentrance (I can demonstrate if you like).

So, EmptyWorkingSet on current process in some particular cases. Other than that - really no needed.

Agree with you. Thanks! Edited by Hammerfist
Link to comment
Share on other sites

@Hammerfist

Still usefull according to me.

I ran this regularly on a process like SKYPE.

These kind of P2P applications like to be greedy if it comes up to memory consumption.

Especially when you have your machine running for a long time.

And performance wise this does not have any influence. Since those apps are sitting waiting in the background.

So bottem line is that is does make sence on certain processes. And for others it doesn't. :D

Regards,

ptrex

Link to comment
Share on other sites

  • 5 months later...

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...