Jump to content
Sign in to follow this  
Who

Reduce mem usage of AutoIt programs ?

Recommended Posts

Who

Nice AutoIT, I have done my auto-work with it and everything works fine :) . But the only trouble is the compiled program needs too much memory on my computer :) that it takes more than 75% of my Mem Usage :P ( 30Mb x 13 ) in Task Manager when my total memory is 512 MB although my program is very simple ( you can see below ). Can anyone please give me a suggestion please :) .

If ProcessExists("pc.exe") Then ProcessClose("pc.exe")
BlockInput(1)
Run("C:\pc.exe","",@SW_MAXIMIZE)
WinActivate("Program Box")
sleep(3000)
Send("{ENTER}")
sleep(3000)
$size = WinGetClientSize("Program")
WinActivate("Program")
WinSetState("Program", "", @SW_MAXIMIZE)
MouseClick("left", 195, 55, 1)

While 1
If WinExists(WinGetTitle("Program Box","Successfully.")) Then
sleep(120000)
Send("{ENTER}")
ExitLoop
EndIf
WEnd

WinActivate("Program")
WinSetState("Program", "", @SW_MAXIMIZE)
MouseClick("left", 195, 55, 1)

While 2
If WinExists(WinGetTitle("Program Box","Done")) Then
sleep(120000)
Send("{ENTER}")
ExitLoop
EndIf
WEnd

Share this post


Link to post
Share on other sites
qazwsx

you could try lowering the priority of you script.

Share this post


Link to post
Share on other sites
enaiman

It looks to me like a matter of processor usage not memory - I can't see how the memory can be "eaten" by your script.

Why I said it looks like a matter of CPU usage? because if the specific tilte - "Program Box","Successfully." or the other one doesn't exist then it will continue to loop endlessly without any sleep. It would be a good idea to put a Sleep(200) or Sleep(100) or whatever value you might consider appropriate in each of the While loops - this way you will give the CPU some sleep time.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
Who

enaiman, I have put the sleep(120000) into my while but nothing change :)

Share this post


Link to post
Share on other sites
ChrisL

This seems a bit extreeem for something that shouldn't use hardly any ram

ReduceMemory(@autoitpid)

If ProcessExists("pc.exe") Then ProcessClose("pc.exe")
BlockInput(1)
Run("C:\pc.exe","",@SW_MAXIMIZE)
WinActivate("Program Box")
sleep(3000)
Send("{ENTER}")
sleep(3000)
;$size = WinGetClientSize("Program");This never gets used so why is it here?
WinActivate("Program")
WinSetState("Program", "", @SW_MAXIMIZE)
MouseClick("left", 195, 55, 1)


While 1
    If WinExists(WinGetTitle("Program Box","Successfully.")) Then
        sleep(120000)
        Send("{ENTER}")
        ExitLoop
    EndIf
    sleep(100)
WEnd

WinActivate("Program")
WinSetState("Program", "", @SW_MAXIMIZE)
MouseClick("left", 195, 55, 1)

While 2
    If WinExists(WinGetTitle("Program Box","Done")) Then
        sleep(120000)
        Send("{ENTER}")
        ExitLoop
    EndIf
    Sleep(100)
WEnd


Func ReduceMemory($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
    
    Return $ai_Return[0]
EndFunc

I can't remember who wrote the ReduceMemory function but it wansn't me!

It was a Zedna w0uter combo by the looks of it!

Edited by ChrisL

Share this post


Link to post
Share on other sites
enaiman

enaiman, I have put the sleep(120000) into my while but nothing change :)

Indeed - but ... that sleep will be used only in case the specific window exists (If condition = True)

Put another Sleep (100) outside - like ChrisL showed in his example.

While 1
    If WinExists(WinGetTitle("Program Box","Successfully.")) Then
        sleep(120000)
        Send("{ENTER}")
        ExitLoop
    EndIf
    sleep(100)   ;<---- this Sleep I'm talking about
WEnd

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
Who

Thank you very much for your answers. Now the program runs 10x faster than before :) and I will keep this in mind for later use :P.

Share this post


Link to post
Share on other sites
Fabry

reducememory function

Func _ReduceMemory($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
 
     Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

For other autoit snippets here

Edited by Fabry

A lan chat (Multilanguage)LanMuleFile transferTank gameTank 2 an online game[center]L'esperienza รจ il nome che tutti danno ai propri errori.Experience is the name everyone gives to their mistakes.Oscar Wilde[/center]

Share this post


Link to post
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
Sign in to follow this  

×