Jump to content

_ReduceMemory UDF


Recommended Posts

this is the UDF

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()

i am newbie please tell me how to use it.

Example of my Code:

opt("WinTitleMatchMode", 2)
Func _MinimizeToTray($fStartup = False)
    $fUpdateMeminfo = False
    If Not $fStartup Then GUISetState(@SW_HIDE)
    TraySetState()
    AdlibDisable()
EndFunc
If WinExists("AutoIt Forums") Then
    WinSetState("AutoIt Forums", "", @SW_SHOW)
     ToolTip("You Are Visiting Autoit Forums Right Noe", 400, 300, "Message", 2, 2)
EndIf
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main", "Window Title", "REG_SZ", "I Love AutoIt")

anyone will tell me about it?

sorry for my spelling mistakes. its due to be fast !!!

Link to comment
Share on other sites

If you want to reduce the memory usage of your current AutoIt process then

_ReduceMemory(@AutoItPid)


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()
Link to comment
Share on other sites

If you want to reduce the memory usage of your current AutoIt process then

_ReduceMemory(@AutoItPid)


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()
where to add it in my script and do i need to call this function again and again?

sorry for my spelling mistakes. its due to be fast !!!

Link to comment
Share on other sites

  • Moderators

The function empties the working set of the application, as the application continues to go on, the working set builds up again. So the answer is yes, to empty the working set, you'll have to call when ever you want this action to happen.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

where to add it in my script and do i need to call this function again and again?

The script you provided would run for about 2 milliseconds then exit it has no need for this function at all.

If you don't know where to use it then I don't think you need to use it at all.

Why do you think you need to use it?

Link to comment
Share on other sites

The script you provided would run for about 2 milliseconds then exit it has no need for this function at all.

If you don't know where to use it then I don't think you need to use it at all.

Why do you think you need to use it?

The script i provided was just a example script (not origional part of program code). i want to use it in my script because i think it is useful code. and this is the only reason why i want to use it. i want to learn about it. it will help to reduce memory size in all scripts which will be good for pc.

Edited by FastHelper

sorry for my spelling mistakes. its due to be fast !!!

Link to comment
Share on other sites

The script i provided was just a example script (not origional part of program code). i want to use it in my script because i think it is useful code. and this is the only reason why i want to use it. i want to learn about it. it will help to reduce memory size in all scripts which will be good for pc.

Well then we can't really tell you where to put it.

If you were using a lot of memory at some point in your script then doing very little you might want to call the function.

From what I've seen it pretty much dumps what it can to virtual memory reduces the physical ram usage but increases the virtual ram usage. Not so good because virtual memory runs slower.

Windows is quite capable of doing this when it needs to anyway

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