Jump to content
Sign in to follow this  

Find memory usage of process

Recommended Posts


I'm looking for a way to find the memory usage of a process, is there a simple way to do this?

Share this post

Link to post
Share on other sites

Global Const $PROCESS_VM_READ = 0x10


Func _ProcessGetMemoryUsage($sProcess)
    ;get process ID
    $nPID = ProcessExists($sProcess)
    If $nPID = 0 Then Return -1
    ;get process handle, required for GetProcessMemoryInfo
    $aRet = DllCall("Kernel32.dll", "int", "OpenProcess", _
                                        "dword", $PROCESS_QUERY_INFORMATION+$PROCESS_VM_READ, "dword", False, "dword", $nPID)
    If @error Or ($aRet[0] = 0) Then Return -1
    $hProc = $aRet[0]
    ;create PPROCESS_MEMORY_COUNTERS to receive data, required for GetProcessMemoryInfo
    $structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword; dword; uint peakmemsize; uint memsize; uint; uint; uint; uint; uint; uint")
    $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
    ;call GetProcessMemoryInfo
    $aRet = DllCall("Psapi.dll", "int", "GetProcessMemoryInfo", _
                                        "hwnd", $hProc, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize)
    ;close process handle
    DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hProc)
    ;return memory size in kb
    Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "memsize") / 1024

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post

Link to post
Share on other sites

Thanks for the awesome quick responses.

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