Jump to content

need help with SetProcessWorkingSetSize


Recommended Posts

I have this code in a larger program:

$ProgramName="test123"
Global $TopWin = GUICreate($ProgramName, ....)
Global $Handle = WinGetHandle($ProgramName)

Dim $v_dll = "Kernel32.dll"
DllCall($v_dll, 'int', 'SetProcessWorkingSetSize', 'hwnd', $Handle, -1, -1 )

I then compile the script to a .exe This should reduce the memory footprint of the running AutoIt-Compiled process, but it does not. I am not familiar with DllCall, but suspect that $Handle is not right.

Here is the info on the SetProcessWorkingSetSize()

http://msdn.microsoft.com/library/default....kingsetsize.asp

Alternatively, I could use EmptyWorkingSet() which uses psapi.dll, but could not get it to work either.

http://msdn.microsoft.com/library/default....yworkingset.asp

Any ideas on how to get this working would be greatly appreciated.

Thanks,

-John

Link to comment
Share on other sites

AFAIK.

handle should be from an OpenProcess call.

you can get one from my memory functions. (see my sig)

also you dllcall syntax is wrong. it should be something LIKE:

DllCall($v_dll, 'int', 'SetProcessWorkingSetSize', 'long', $Handle, 'long', -1, 'long', -1 )
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

No luck. :)

I tried this:

Global $Handle = _MemOpen($MEM_W, False, ProcessExists('Remote_Manager.exe'))
; and MEM_R, MEM_O
Dim $rc = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $Handle)

Also this:

Dim $rc = DllCall("Kernel32.dll", 'int', 'SetProcessWorkingSetSize', 'long', $Handle, 'long', -1, 'long', -1 )

Any other ideas?

-John

Link to comment
Share on other sites

you had insufficent access. this works for me.

Global Const $PROCESS_ALL_ACCESS = 0x1f0fff
Global Const $PROCESS_CREATE_PROCESS = 128
Global Const $PROCESS_CREATE_THREAD = 2
Global Const $PROCESS_DUP_HANDLE = 64
Global Const $PROCESS_QUERY_INFORMATION = 1024
Global Const $PROCESS_SET_INFORMATION = 512
Global Const $PROCESS_TERMINATE = 1
Global Const $PROCESS_VM_OPERATION = 8
Global Const $PROCESS_VM_READ = 16
Global Const $PROCESS_VM_WRITE = 32


Global $Handle = _MemOpen($PROCESS_ALL_ACCESS, False, $PID)
Dim $rc = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $Handle)



Func _MemOpen($i_dwDesiredAccess, $i_bInheritHandle, $i_dwProcessId)
    
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $i_dwDesiredAccess, 'int', $i_bInheritHandle, 'int', $i_dwProcessId)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    
    Return $ai_Handle[0]
EndFunc;==> _MemOpen()
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Awesome. This totally works. Maybe you could add this to your mem.au3?

Before using the DllCall, my program used 4036 KB of memory and after using it is used 1688 KB -- a difference of 2348 KB (59% less memory). I do not see any difference in performance, either.

-John

Edited by jftuga
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...