How to get current free physical memory ?

  • Thread starter Thread starter Peter Stojkovic
  • Start date Start date
P

Peter Stojkovic

Using VS 2003 and Windows XP

How can I get free physical memory ??

Where is a full documentation for WMI and so an managementobjects ?


Peter
 
TOP A:
To get FreePhysicalMemory
via
"Select FreePhysicalMemory from win32_operatingsystem"

we need 600ms .
That's a long time.


TOP B:
A full select
"Select * from win32_operatingsystem"
needs 10 seconds !!!!!




Is there any quicker/other possibility to get amount of free memory ??


Peter
 
Add reference to 'System.Management' DLL

Add the following Import statement

Imports System.Management

Add this function:

Private Function GetFreePhysicalMemory() As String
Dim objMgmt As ManagementObject
Dim objOs As ManagementObjectSearcher = _
New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim strResult As String
For Each objMgmt In objOs.Get
strResult = objMgmt("freephysicalmemory").ToString()
Next
objOs.Dispose()
objMgmt.Dispose()
Return strResult
End Function

Usage:

MessageBox.Show(GetFreePhysicalMemory)

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
 
Thanks,

but this needs so much time to execute as described in my last mail !

Peter
 
Thanks a lot.

That is much qicker than,
"SELECT * from win32_...."

Peter
 
Peter Stojkovic said:
That is much qicker than,
"SELECT * from win32_...."

WMI was primarily designed to to /management/ operations easily, so
performance was not that important. In addition to my previous reply, you
may want to take a look at the 'MemoryStatusEx' function, which is more
evolved than the 'MemoryStatus' function I use in the sample.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top