>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Hi;
I have a application trying to do something if there is not enough
memory
usage. I am wondering is there any way to know from VB inclusive of API
what
is the system memory usage currently (i.e the statistic display in memory
usage section of performance column).
If you have any sample which I can follow, I would very much
appreciated.
Thanks and regards.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Try:
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As
MEMORYSTATUS)
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@A...
Dim MemStat As MEMORYSTATUS
'retrieve the memory status
GlobalMemoryStatus MemStat
MsgBox "You have" + Str$(MemStat.dwTotalPhys / 1024) + " Kb total
memory and" + Str$(MemStat.dwAvailPageFile / 1024) + " Kb available
PageFile memory."
End Sub
'I also used it in:
Public Property Get AvailableVirtualMem() As Double
' Get free memory.
Dim ldblResult As Double
Dim lusrMemStatus As MEMORYSTATUS
Dim llngMemory As Long
' Get the memory status from API
GlobalMemoryStatus lusrMemStatus
' Available Virtual Mem
llngMemory& = lusrMemStatus.dwAvailVirtual
ldblResult = Format(llngMemory \ 1024, "###,###,###")
' Return the result
AvailableVirtualMem = ldblResult
End Property
Public Property Get AvailablePhysicalMem() As Double
' Get free memory.
Dim ldblResult As Double
Dim lusrMemStatus As MEMORYSTATUS
Dim llngMemory As Long
' Get the memory status from API
GlobalMemoryStatus lusrMemStatus
' Parse up the info nicely for displaying
' Available Physical Mem
llngMemory& = lusrMemStatus.dwAvailPhys
ldblResult = Format(llngMemory \ 1024, "###,###,###")
' Return the result
AvailablePhysicalMem = ldblResult
End Property
Public Property Get AvailableMemory() As Double
' Get free memory.
Dim ldblResult As Double
' Add the two Availables together
ldblResult = AvailablePhysicalMem + AvailableVirtualMem
' Return the result
AvailableMemory = ldblResult
End Property
Hope that helps
Andrew
PS: That does not tell you how much memory your process is telling you
though! Try the kpd team website for more info on APIs