Sign in to follow this  
Followers 0
VicTT

GetUsedMemory()

2 posts in this topic

#1 ·  Posted (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 :D

EDIT: Edited CODE with Smoke's version..Thankies :wacko:..Never really thought

SetError($error)
Return

can be neatly written as a one-liner like this:

Return SetError($error,0,0)
Edited by VicTT

[quote]Together we might liveDivided we must fall[/quote]

Share this post


Link to post
Share on other sites



awesome!

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  
Followers 0