The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: hutch-- on August 19, 2009, 04:42:07 AM

Title: Please test memory status code.
Post by: hutch-- on August 19, 2009, 04:42:07 AM
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
Title: Re: Please test memory status code.
Post by: 2-Bit Chip on August 19, 2009, 06:10:58 AM
Works flawless for me. :bg
Title: Re: Please test memory status code.
Post by: MichaelW on August 19, 2009, 06:46:48 AM
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."
Title: Re: Please test memory status code.
Post by: jj2007 on August 19, 2009, 06:51:30 AM
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
Title: Re: Please test memory status code.
Post by: hutch-- on August 19, 2009, 07:41:13 AM
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.
Title: Re: Please test memory status code.
Post by: 2-Bit Chip on August 19, 2009, 07:55:50 AM
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 ...