[AccessD] How to tell how much resources have been used
Bill Benson
bensonforums at gmail.com
Sun Jun 7 11:57:56 CDT 2015
Here is another combination of APIs that I have no idea how they work but
appears to gather how much memory is being used by the current process, and
I hope is reliable since I am going to go with it...
Option Compare Database
Option Explicit
Type PROCESS_MEMORY_COUNTERS
cb As Long
PageFaultCount As Long
PeakWorkingSetSize As Long
WorkingSetSize As Long
QuotaPeakPagedPoolUsage As Long
QuotaPagedPoolUsage As Long
QuotaPeakNonPagedPoolUsage As Long
QuotaNonPagedPoolUsage As Long
PagefileUsage As Long
PeakPagefileUsage As Long
End Type
Private Const PROCESS_QUERY_INFORMATION = 1024
Private Const PROCESS_VM_READ = 16
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess
As Long, lphModule As Long, ByVal cb As Long, lpcbNeeded As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal
dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As
Long) As Long
Private Declare Function GetProcessMemoryInfo Lib "PSAPI.DLL" (ByVal
hProcess As Long, ppsmemCounters As PROCESS_MEMORY_COUNTERS, ByVal cb As
Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal Handle As
Long) As Long
Public Function GetCurrentProcessMemory() As Long
Dim lngCBSize2 As Long
Dim lngModules(1 To 200) As Long
Dim lngReturn As Long
Dim lngHwndProcess As Long
Dim pmc As PROCESS_MEMORY_COUNTERS
Dim lRet As Long
Dim MemDelta As Long
Static MemUsed As Long
'Get a handle to the Process and Open
lngHwndProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or
PROCESS_VM_READ, 0, GetCurrentProcessId)
If lngHwndProcess <> 0 Then
'Get an array of the module handles for the specified process
lngReturn = EnumProcessModules(lngHwndProcess, lngModules(1), 200,
lngCBSize2)
'If the Module Array is retrieved, Get the ModuleFileName
If lngReturn <> 0 Then
'Get the Site of the Memory Structure
pmc.cb = LenB(pmc)
lRet = GetProcessMemoryInfo(lngHwndProcess, pmc, pmc.cb)
GetCurrentProcessMemory = pmc.WorkingSetSize
End If
End If
'Close the handle to this process
lngReturn = CloseHandle(lngHwndProcess)
End Function
More information about the AccessD
mailing list