News:

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

Updated memory status algo.

Started by hutch--, August 22, 2009, 10:23:42 AM

Previous topic - Next topic

hutch--

I altered the code so it took the 64 bit values and divided them by 1 megabyte to get the results into an easily manageable form. The last value in the structure is reserved so I did not return it as its always zero.

I get these results on my box.


91%  memory free

3326 megabytes installed physical memory
3023 megabytes available physical memory

7280 megabytes maximum page file size
7107 megabytes available page file

3072 megabytes total virtual memory
3067 megabytes available virtual memory

Press any key to continue ...


Test piece.


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

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

    GetMemoryStatus PROTO :DWORD

      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 pfree     :DWORD
    LOCAL mst       :MEMORYSTATUS

    mov pfree, rv(GetMemoryStatus,ADDR mst)

    print ustr$(mst.dwMemoryLoad),"%  memory free",13,10,13,10

    print ustr$(mst.dwTotalPhys)," megabytes installed physical memory",13,10
    print ustr$(mst.dwAvailPhys)," megabytes available physical memory",13,10,13,10

    print ustr$(mst.dwTotalPageFile)," megabytes maximum page file size",13,10
    print ustr$(mst.dwAvailPageFile)," megabytes available page file",13,10,13,10

    print ustr$(mst.dwTotalVirtual)," megabytes total virtual memory",13,10
    print ustr$(mst.dwAvailVirtual)," megabytes available virtual memory",13,10,13,10

    ret

main endp

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

GetMemoryStatus proc pmst:DWORD

    LOCAL mse       :xMEMORYSTATUSEX
    LOCAL divd      :DWORD

    push esi

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

    mov esi, pmst

    mov divd, 1024 * 1024

    fild mse.ullTotalPhys
    fild divd
    fdiv                                                    ; divide 64 bit total by 1 megabyte
    fistp (MEMORYSTATUS PTR [esi]).dwTotalPhys              ; write total to struct

    fild mse.ullAvailPhys
    fild divd
    fdiv
    fistp (MEMORYSTATUS PTR [esi]).dwAvailPhys              ; write available to struct

    fild mse.ullTotalPageFile
    fild divd
    fdiv
    fistp (MEMORYSTATUS PTR [esi]).dwTotalPageFile          ; page file total

    fild mse.ullAvailPageFile
    fild divd
    fdiv
    fistp (MEMORYSTATUS PTR [esi]).dwAvailPageFile          ; page file available

    fild mse.ullTotalVirtual
    fild divd
    fdiv
    fistp (MEMORYSTATUS PTR [esi]).dwTotalVirtual           ; total virtual

    fild mse.ullAvailVirtual
    fild divd
    fdiv
    fistp (MEMORYSTATUS PTR [esi]).dwAvailVirtual           ; available virtual

    mov eax, 100
    sub eax, mse.dwMemoryLoad
    mov (MEMORYSTATUS PTR [esi]).dwMemoryLoad, eax          ; memory load % free

    pop esi

    ret

GetMemoryStatus endp

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

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

jj2007

Quote from: hutch-- on August 22, 2009, 10:23:42 AM
I altered the code so it took the 64 bit values and divided them by 1 megabyte to get the results into an easily manageable form. The last value in the structure is reserved so I did not return it as its always zero.

I get these results on my box.


Looks good :U

56%  memory free

1015 megabytes installed physical memory
562 megabytes available physical memory

1674 megabytes maximum page file size
1306 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory

dedndave

it brings to mind how badly i need to upgrade
1 gb used to be a bunch - lol
this machine has 4 sim slots with 256 mb each (400 MHz DDR)
i guess that means all new stuff

58%  memory free

1015 megabytes installed physical memory
584 megabytes available physical memory

2442 megabytes maximum page file size
2163 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory

MichaelW

I can verify the first four values, but not the last three using System Information, Performance Monitor, or Task Manager.

56%  memory free

512 megabytes installed physical memory
283 megabytes available physical memory

1248 megabytes maximum page file size
982 megabytes available page file

2048 megabytes total virtual memory
2036 megabytes available virtual memory


Per System Information the total virtual memory is 1,802,116 KB and the available virtual memory 1,289,224 KB. Per Performance Monitor the page file usage is 6.5%, where 1248/982 = 0.21.
eschew obfuscation

dedndave

page file info -
Control Panel - System icon - Advanced tab - Performance "Settings" button - Advanced tab - "Change" button

the current sie of my page file is 1.48 gb
i had mine set to 3048 mb maximum (dunno where i got that number - lol)
i changed it to 3072 mb...

57%  memory free

1015 megabytes installed physical memory
578 megabytes available physical memory

2442 megabytes maximum page file size
2146 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory

MichaelW

That gives me 768-1536 MB for the page file.

eschew obfuscation

dedndave

you might be able to get a little performance boost by bumping the max up a little, Michael
2560 would probably be a good number

MichaelW

Experimenting with larger page file sizes, I have never been able to detect any increase in performance so I just leave it at the default. To me it's like overclocking your processor by 10% - if you can't tell the difference, why bother.

eschew obfuscation

FORTRANS

Hi,


53%  memory free

255 megabytes installed physical memory
133 megabytes available physical memory

258 megabytes maximum page file size
148 megabytes available page file

2048 megabytes total virtual memory
2043 megabytes available virtual memory


   Bleah.  Page file is different  from that specified in the System
tool in control panel.

Steve N.

dedndave

it is for everyone, Steve - to get the numbers to match, some calculation has to be done, i think

Michael - it depends a lot on how you use the machine
many users never run 2 programs at the same time that make use of a lot of memory
if you run excel with a sizable spread-sheet and word with a sizable doc, you'll notice a difference

ecube

Quote from: dedndave on August 22, 2009, 12:45:56 PM
it is for everyone, Steve - to get the numbers to match, some calculation has to be done, i think

Michael - it depends a lot on how you use the machine
many users never run 2 programs at the same time that make use of a lot of memory
if you run excel with a sizable spread-sheet and word with a sizable doc, you'll notice a difference

Au crontaire! :bg I intentionally go out of my way to run everything at once to try and slow down my new pc, so far I haven't been successful, but atleast i'm getting the bang for my buck  :U Anyone who's upgraded recently I recommend you do the same, atleast now while man is > machine. When they evolve and kill us all it'll be to late :P

hutch--

The only values I consider useful are the memory used, installed memory and the available memory. On my win2k I have the page file set to 4092 which is just under the limit and I think with the memory installed that it probably never gets used.

The numbers returned by the function are those returned by GlobalMemoryStatusEx() divided by one megabyte simply so it would easily fit into a DWORD sized memory operand but the current MSDN reference for the function says that the virtual memory and page file used values are volatile which I guess says they are not all that much use. I added the rest apart from the last one which is reserved simply because they were there, not because they were of much use.

The memory available value is actually useful if you need to know how much memory can be allocated for a large task and it means that at the time of allocation you can leave a safety margin but allocate the largest block possible if the task requires very large memory.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Rsir

build and runs smoothly

34%  memory free

1013 megabytes installed physical memory
342 megabytes available physical memory

2513 megabytes maximum page file size
731 megabytes available page file

2048 megabytes total virtual memory
2038 megabytes available virtual memory


after cleaning-up memory a bit:

38%  memory free

1013 megabytes installed physical memory
378 megabytes available physical memory

2513 megabytes maximum page file size
1202 megabytes available page file

2048 megabytes total virtual memory
2038 megabytes available virtual memory


katsyonak

72%  memory free

3327 megabytes installed physical memory
2395 megabytes available physical memory

5210 megabytes maximum page file size
4328 megabytes available page file

2048 megabytes total virtual memory
2042 megabytes available virtual memory

Press any key to continue ...

BlackVortex

Works fine on Win7 64-bit :

71%  memory free

4095 megabytes installed physical memory
2867 megabytes available physical memory

8189 megabytes maximum page file size
6809 megabytes available page file

2048 megabytes total virtual memory
2037 megabytes available virtual memory