Jump to content

_ReduceMemory UDF


jftuga
 Share

Recommended Posts

A joke...

Here's my take on this:

;_ReduceMemory Example
Global $Ret = _ReduceMemory()
ConsoleWrite('_ReduceMemory: Return='& $Ret &' @error=' & @error &@lf)
Sleep(10000)

;_ReduceMemory UDF
Func _ReduceMemory($PID = 0)
    ; Discussion: http://www.autoitscript.com/forum/topic/13399-reducememory-udf
    ; Description: Removes as many pages as possible from the working set of the specified process.
    ; Return: Success = 1, Failure = 0
    ; Based on _WinAPI_EmptyWorkingSet by Yashied w/ proper access flags
    Local $Ret
    If (Not $PID) Then
        $Ret = DllCall("kernel32.dll", "handle", "GetCurrentProcessId")
        If @error Or (Not $Ret[0]) Then Return SetError(1, 0, 0)
        $PID = $Ret[0]
    EndIf
    Local $hProcess = DllCall('kernel32.dll', 'ptr', 'OpenProcess', 'dword', 0x00000700, 'int', 0, 'dword', $PID)
    If (@error) Or (Not $hProcess[0]) Then Return SetError(2, 0, 0)
    Local $Ret = DllCall(@SystemDir & '\psapi.dll', 'int', 'EmptyWorkingSet', 'ptr', $hProcess[0])
    If (@error) Or (Not $Ret[0]) Then $Ret = 0
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'ptr', $hProcess[0])
    If Not IsArray($Ret) Then Return SetError(3, 0, 0)
    Return 1
EndFunc   ;==>_ReduceMemory
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...