Home All Groups Group Topic Archive Search About

How to get current free physical memory ?

Author
6 Apr 2005 11:11 AM
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

Author
6 Apr 2005 12:43 PM
Peter Stojkovic
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


Show quoteHide quote
"Peter Stojkovic" <Peter.Stojko***@gmx.net> wrote in message
news:uqBA4lpOFHA.3856@TK2MSFTNGP10.phx.gbl...
> 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
>
>
>
Author
6 Apr 2005 1:37 PM
Crouchie1998
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
Author
6 Apr 2005 4:04 PM
Peter Stojkovic
Thanks,

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

Peter


Show quoteHide quote
"Crouchie1998" <crouchie1998@spamcop.net> wrote in message
news:O44Ru3qOFHA.2136@TK2MSFTNGP14.phx.gbl...
> 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
>
>
Author
6 Apr 2005 4:33 PM
Herfried K. Wagner [MVP]
"Peter Stojkovic" <Peter.Stojko***@gmx.net> schrieb:
> Using VS 2003 and Windows XP
>
> How can I get free physical memory ??

<URL:http://dotnet.mvps.org/dotnet/samples/operatingsystem/MemoryStatus.zip>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 9:43 AM
Peter Stojkovic
Thanks a lot.

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

Peter



Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:ekeLNZsOFHA.3704@TK2MSFTNGP12.phx.gbl...
> "Peter Stojkovic" <Peter.Stojko***@gmx.net> schrieb:
>> Using VS 2003 and Windows XP
>>
>> How can I get free physical memory ??
>
> <URL:http://dotnet.mvps.org/dotnet/samples/operatingsystem/MemoryStatus.zip>
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
8 Apr 2005 12:52 PM
Herfried K. Wagner [MVP]
"Peter Stojkovic" <Peter.Stojko***@gmx.net> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>