PDA

Показать полную графическую версию : [решено] Получение объема выделенной памяти для приложения.


HORRIBLE
12-10-2009, 22:02
Как получить объем оперативной памяти, который взяло себе приложение. Т.е. то число которое мы видим в диспетчере устройств.

Creat0R
12-10-2009, 22:46
MsgBox (http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm)(0, "", _ProcessGetMemory("AutoIt3.exe") & " kb")

Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _ProcessGetMemory($nPID)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $PROCESS_QUERY_INFORMATION = 0x400
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) Const (http://www.autoitscript.com/autoit3/docs/keywords.htm#Const) $PROCESS_VM_READ = 0x10

;get process ID
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) IsString (http://www.autoitscript.com/autoit3/docs/functions/IsString.htm)($nPID) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) $nPID = ProcessExists (http://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm)($nPID)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $nPID = 0 Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) -1

;get process handle, required for GetProcessMemoryInfo
$aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("Kernel32.dll", "int", "OpenProcess", "dword", _
$PROCESS_QUERY_INFORMATION+$PROCESS_VM_READ, "dword", False (http://www.autoitscript.com/autoit3/docs/keywords.htm#False), "dword", $nPID)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Or (http://www.autoitscript.com/autoit3/docs/keywords.htm#Or) ($aRet[0] = 0) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) -1

$hProc = $aRet[0]

;create PPROCESS_MEMORY_COUNTERS to receive data, required for GetProcessMemoryInfo
$structPROCESS_MEMORY_COUNTERS = DllStructCreate (http://www.autoitscript.com/autoit3/docs/functions/DllStructCreate.htm)("dword;dword;uint peakmemsize;uint memsize;uint;uint;uint;uint;uint;uint")
$nSize = DllStructGetSize (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetSize.htm)($structPROCESS_MEMORY_COUNTERS)

;call GetProcessMemoryInfo
$aRet = DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("Psapi.dll", "int", "GetProcessMemoryInfo", _
"hwnd", $hProc, "ptr", DllStructGetPtr (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetPtr.htm)($structPROCESS_MEMORY_COUNTERS), "dword", $nSize)

;close process handle
DllCall (http://www.autoitscript.com/autoit3/docs/functions/DllCall.htm)("Kernel32.dll", "int", "CloseHandle", "hwnd", $hProc)

;return memory size in kb
Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) DllStructGetData (http://www.autoitscript.com/autoit3/docs/functions/DllStructGetData.htm)($structPROCESS_MEMORY_COUNTERS, "memsize") / 1024
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc)




© OSzone.net 2001-2012