[AccessD] How to tell how much resources have been used

Bill Benson bensonforums at gmail.com
Sun Jun 7 08:19:15 CDT 2015


Jack - thank you. Those are two helful links to be sure! I rewrote the
function. I don't understand a couple of things.

One, I thought that it was reporting on global memory availability and/or
usage, not any portion specific to the instance of Access I am in. Yet when
I run it, it seems to come up with a value like
   0.5 when I first open the database
   1.03 when have run the first batch of reports

If I open another instance of Access (same database), the numbers are again
0.5 when I first open the database
1.0x when have run the first batch of reports

So it would appear to somehow be reporting on memory conditions local to
the application I am using - which frankly I do not understand, given the
nature of the APIs construction. How (given the two parameters passed) - is
this function able to report only on what the local app is using? I don't
mean to look a gift horse in the mouth - as it is doing EXACTLY what I need
it to be doing ... but I would like to know how/why before I trust this for
my purpose.

Another issue:  I read this on MSDN (https://goo.gl/HKwjkL):

                   "On computers with more than 4 GB of memory, the
*MEMORYSTATUS* structure can return incorrect information,
                     reporting a value of –1 to indicate an overflow. If
your application is at risk for this behavior,
                     use the *GlobalMemoryStatusEx*
<https://msdn.microsoft.com/en-us/library/windows/desktop/aa366589(v=vs.85).aspx>
function instead of the *GlobalMemoryStatus*
<https://msdn.microsoft.com/en-us/library/windows/desktop/aa366586(v=vs.85).aspx>
function"

I have 8GB RAM and GlobalMemory seems to work, but I tried instead using
GlobalMemoryStatusEx based on example code here (http://goo.gl/sxBJbG).

Now I get a negative result, not even similar in magnitude.

Seeing my intent, can you (or anyone) tell me what I may be doing wrong in
my MemoryEXUsed function below? Also, how would I know a user of this
application is "at risk" of falling afoul of *MEMORYSTATUS* limitations,
seeing that for me, on my system - which is > 4GB - it appears to work well
enough?


Thanks again for that post!



Option Compare Database
Option Explicit
Private Type ULARGE_INTEGER
  LowPart As Long
  HighPart As Long
End Type
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 Type MEMORY_STATUS_EX
    dwLength As Long
    dwMemoryLoad As Long
    ullTotalPhys As ULARGE_INTEGER
    ullAvailPhys As ULARGE_INTEGER
    ullTotalPageFile As ULARGE_INTEGER
    ullAvailPageFile As ULARGE_INTEGER
    ullTotalVirtual As ULARGE_INTEGER
    ullAvailVirtual As ULARGE_INTEGER
    ullAvailExtendedVirtual As ULARGE_INTEGER
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As _
            MEMORYSTATUS)
Private Declare Function GlobalMemoryStatusEx Lib "kernel32.dll" (lpBuffer
As MEMORY_STATUS_EX) As Long
'Private Declare Sub GlobalMemoryStatus Lib "kernel32.dll" (lpBuffer As
MEMORY_STATUS)
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory"
(Destination As Any, Source As Any, ByVal Length As Long)

Function MemoryEXUsed()
Dim MemTemp As Currency
Dim X As MEMORY_STATUS_EX
Dim AvailVirtualMem
Dim VirtualMem
X.dwLength = Len(X)
GlobalMemoryStatusEx X
CopyMemory MemTemp, X.ullAvailPageFile, Len(MemTemp)
AvailVirtualMem = MemTemp
CopyMemory MemTemp, X.ullTotalVirtual, Len(MemTemp)
VirtualMem = MemTemp
Debug.Print "VM: " & VirtualMem, "AVM: " & AvailVirtualMem
MemoryEXUsed = VirtualMem - AvailVirtualMem
Exit Function
'        CopyMemory MemTemp, X.ullAvailPhys, Len(MemTemp)
'        AvailMem = MemTemp
'        AvailPageMem = Str(MemTemp)
'        CopyMemory MemTemp, X.ullAvailVirtual, Len(MemTemp)
'        LoadMem = Str(X.dwMemoryLoad)
'        CopyMemory MemTemp, X.ullTotalPageFile, Len(MemTemp)
'        PageMem = Str(MemTemp)
'        CopyMemory MemTemp, X.ullTotalPhys, Len(MemTemp)
'        PhysicalMem = Str(MemTemp)
End Function

Function MemoryUsed()
Dim msg As String         ' Status information.
Dim memsts As MEMORYSTATUS
GlobalMemoryStatus memsts
MemoryUsed = Format((memsts.dwTotalVirtual - memsts.dwAvailVirtual) /
1073741824, "0.000")
End Function

On Sun, Jun 7, 2015 at 8:21 AM, jack drawbridge <jackandpat.d at gmail.com>
wrote:

> Bill,
>
> I have never used the api and am not familiar with it.
> I did find this from years ago re negative values.
>
> http://bytes.com/topic/access/answers/208402-a97-why-negative-memory-values-reported
>
> And this:
>
> http://stackoverflow.com/questions/19550367/access-2010-system-resource-exceeded
>
> Good luck.
>
>


More information about the AccessD mailing list