News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Please test memory status code.

Started by hutch--, August 19, 2009, 04:42:07 AM

Previous topic - Next topic

hutch--

This looks like it works OK. I have 3 boxes, 2 with over 2 gig of memory and it seems to match the OS results.

These are the results on this box with 4 gig.


The operation completed successfully.

91 % --- free physical memory
3325 --- Total physical memory
3007 --- Available physical memory
Press any key to continue ...


This is the test code.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

      xMEMORYSTATUSEX STRUCT
        dwLength                    DWORD ?
        dwMemoryLoad                DWORD ?
        ullTotalPhys                QWORD ?
        ullAvailPhys                QWORD ?
        ullTotalPageFile            QWORD ?
        ullAvailPageFile            QWORD ?
        ullTotalVirtual             QWORD ?
        ullAvailVirtual             QWORD ?
        ullAvailExtendedVirtual     QWORD ?
      xMEMORYSTATUSEX ENDS

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    LOCAL mst       :xMEMORYSTATUSEX
    LOCAL pused     :DWORD
    LOCAL mTotal    :DWORD
    LOCAL mAvail    :DWORD

    mov mst.dwLength, SIZEOF xMEMORYSTATUSEX                ; initialise length
    invoke GlobalMemoryStatusEx,ADDR mst                    ; call API

    print LastError$(),13,10                                ; display success

    mov eax, DWORD PTR mst.ullTotalPhys                     ; get 1st DWORD of total
    mov mTotal, eax

    mov eax, DWORD PTR mst.ullAvailPhys                     ; get 1st DWORD of available
    mov mAvail, eax

    shr mTotal, 20                                          ; convert to MB
    shr mAvail, 20

    mov pused, rv(IntDiv,mAvail,rv(IntDiv,mTotal,100))      ; calculate percentage

  ; ---------------
  ; display results
  ; ---------------
    print ustr$(pused)," % --- free physical memory",13,10
    print ustr$(mTotal)," --- Total physical memory",13,10
    print ustr$(mAvail)," --- Available physical memory",13,10

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

2-Bit Chip


MichaelW

In my results the numbers are very close to what the system reports, but the error message is just a leftover from my last misadventure.

The system cannot find the file specified.

54 % --- free physical memory
511 --- Total physical memory
272 --- Available physical memory
Press any key to continue ...


After I added an "invoke SetLastError, 0" at the start, the error message changed to a more meaningful:

"The operation completed successfully."
eschew obfuscation

jj2007

Impossibile trovare l'opzione di ambiente specificata. (=can't find the specified environment option)

66 % --- free physical memory
1015 --- Total physical memory
662 --- Available physical memory

hutch--

gratsie,

I have plugged it into QE so the about box does not display rubbish for computers with more than 2 gig of memory. Looks like it works OK elsewhere as well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

2-Bit Chip

Works fine for me :dazzled:

The operation completed successfully.

54 % --- free physical memory
3317 --- Total physical memory
1783 --- Available physical memory
Press any key to continue ...