VicTT Posted July 16, 2006 Posted July 16, 2006 (edited) Well...I know this has been done before, but I couldn't find it on the first searches, and had to bump my thread in order to get a constructive reply so I just thought I'd post it here, so that people in my situation may find it... Func _GetUsedMemory($nPID = @AutoItPID) If IsString($nPID) Then $npid = ProcessExists($nPID) If $nPID = 0 Then Return SetError(1, 0, 0) $oWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") If @error Then Return SetError(2, 0, 0) $sQuery = $oWMIService.ExecQuery ("SELECT WorkingSetSize FROM Win32_Process WHERE ProcessId=" & $npid,"WQL",48) If IsObj($sQuery) Then For $sObject In $sQuery Return ($sObject.WorkingSetSize / 1024) Next EndIf EndFunc;==>GetUsedMemory And the program I wanted it for(which was more of a curiosity than anything): Global $max=100000 $init=GetUsedMemory() $t1=TimerInit() for $i=1 to $max Assign("NEW_"&$i,$i) next $t2=TimerDiff($t1) $end=GetUsedMemory() MsgBox(0,"","Allocating "&$max&" ints means sacrificing"&($end-$init)/1024&" KB of memory and took "&$t2&" ms") At least I didn't post a function to calculate the area of a circle when one knows the radius (I've actually seen that)..Hope it's useful to anyone else except me EDIT: Edited CODE with Smoke's version..Thankies ..Never really thought SetError($error) Return can be neatly written as a one-liner like this: Return SetError($error,0,0) Edited July 17, 2006 by VicTT Quote Together we might liveDivided we must fall
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now