News:

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

Meminfo

Started by ToutEnMasm, November 01, 2011, 06:54:21 AM

Previous topic - Next topic

ToutEnMasm


This one use the MEMORYSTATUSEX structure.
The use of the CRT sprintf_s fonction is here to grant a correct display of the qword values in hexadecimal format (shorter).
It use also the libcmt.lib who make it bigger but avoid the "couldn't find msvcNNN.dll"
Let me know if there is problems with it.

dedndave

XP MCE2005 SP3 - prescott w/htt - 1Gb RAM
MessageBox font/size: Tahoma 10 (SystemParametersInfo, NONCLIENTMETRICS.lfMessageFont)



"dwMemoryLoad Percent memory in used"

in English, we would say...
"dwMemoryLoad Percent memory in use"

or...
"dwMemoryLoad Percent memory used"

ToutEnMasm


Wich is the compressor you use . png.zip ? not recognize by 7.zip

fearless

Quote from: ToutEnMasm on November 01, 2011, 10:05:32 AM

Wich is the compressor you use . png.zip ? not recognize by 7.zip


Dave has uploaded a png image to the forum and attached it as a .zip - as the board only allows .zip extensions. Once its in his post he can reference it with bbcode tags:
[img][/img]
ƒearless

Bill Cravener

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

ToutEnMasm

miss the units (it's rounded to thousand ) and the % of memory in use.
:dance:

clive

It could be a random act of randomness. Those happen a lot as well.

ToutEnMasm


To Bill Cravener,
I have made a comparison between Memfree and meminfo .
MemFree give bad results.
Run the two,change the hexadecimal format of the total physical memory in decimal and you would see a difference.
The sprintf_s (crt) couldn't be false,so ...


dedndave

Bill and Yves...

from MSDN
QuoteullAvailExtendedVirtual
    Reserved. This value is always 0.

as for the differences in values, Bill displays Kbytes - Yves displays bytes - they are pretty close on my machine
and - Bill included the source code, Yves did not   :bg
it's easy to see what he did
although, i may have used SHRD instead of DIV

ToutEnMasm


apologies..
I have forgotten the divide by 1024.
Source code is here.
Quote
.NOLIST
.386
.model flat,stdcall
option casemap:none   
   include translate.inc
   include windows.sdk
   include \vc\stdio.sdk
   include \vc\stdlib.sdk
.const
includelib  libcmt.lib ;msvcrt.lib ;
extern c _FPinit:dword   ; to load floating point library
invalid_parameter PROTO C :DWORD,  :DWORD,  :DWORD,  :DWORD,  :DWORD
MemInfo PROTO

;avoid the R6002 floating point not loaded error
.data
invalid db "invalid parameter",0     
;---------------------------------------------------------------------------
caption           db      "    MEMORYSTATUSEX   ",0
fmt               db      "dwMemoryLoad Percent memory in used   :",9,"%d",13,10 
         db      "ullTotalPhys total physical memory     :",9,"%I64Xh",13,10
         db      "ullAvailPhys free physical memory     :",9,"%I64Xh",13,10 
         db      "ullTotalPageFile total paging file     :",9,"%I64Xh",13,10
         db      "ullAvailPageFile free  paging file     :",9,"%I64Xh",13,10
         db      "ullTotalVirtual  total virtual memory     :",9,"%I64Xh",13,10
         db      "ullAvailVirtual  free  virtual memory     :",9,"%I64Xh",13,10
         db      "ullAvailExtendedVirtual:",9,"%I64Xh",13,10                                    
         db 13,10,0

memstat   MEMORYSTATUSEX <sizeof MEMORYSTATUSEX,,,,,,,,>
asciiz1               db      500 dup(?)
                                 
.code
;################################################################
invalid_parameter PROC C expression:DWORD,function,file,line,pReserved
         Local  retour:DWORD
         mov retour,1
   ;all parameters expression:DWORD,function,file,line,pReserved are NULL   
   invoke MessageBox,NULL,ADDR invalid,NULL,MB_OK
Findeinvalid_parameter:
         mov eax,retour
         ret
invalid_parameter endp

;################################################################
MemInfo PROC
         Local  retour:DWORD
         mov retour,1
push offset memstat                     ; address of MEMORYSTATUS structure
call GlobalMemoryStatusEx                 ; call to GlobalMemoryStatus API function
lea edx,memstat.ullTotalPhys

invoke sprintf_s,addr asciiz1,sizeof asciiz1,addr fmt,memstat.dwMemoryLoad,memstat.ullTotalPhys,
         memstat.ullAvailPhys,memstat.ullTotalPageFile,memstat.ullAvailPageFile,
         memstat.ullTotalVirtual,memstat.ullAvailVirtual,memstat.ullAvailExtendedVirtual,
         memstat.dwMemoryLoad
   

invoke MessageBox,0,addr asciiz1,addr caption,0                                             

FindeMemInfo:
         mov eax,retour
         ret
MemInfo endp

;################################################################
   
WinMain proc hInst:DWORD,hPrevInst:DWORD,lpCmdLine:DWORD,nShowCmd:DWORD
   invoke _set_invalid_parameter_handler,invalid_parameter
   invoke MemInfo
   mov eax,0
   ret
WinMain endp

Bill Cravener

Dave,

Well you should know my stuff by now. I don't always use the most efficient way. I prefer to show beginners the simplest most explanatory way. :bg


Tout,

Whats that I see? You using C libraries? My version is only 4K, whats the size of your version? Come on now, that's not the asm way to do things buddy! :bg

My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat

clive

Quote from: dedndavealthough, i may have used SHRD instead of DIV

Although you really need something that dynamically scales, because the simple DIV 1024 breaks down on numbers bigger than 2^42 (say about 4TB), but more importantly it's hard to decipher the decimal places at a glance.

SHRD won't overflow using two shifts, but might have a slower throughput than DIV.
It could be a random act of randomness. Those happen a lot as well.

jj2007

Quote from: clive on November 01, 2011, 05:09:21 PM...but more importantly it's hard to decipher the decimal places at a glance.

SHRD won't overflow using two shifts, but might have a slower throughput than DIV.

Please take the slowest instruction available. At my age, deciphering the decimal places takes a few nanoseconds more :8)

ToutEnMasm


Quote
Whats that I see? You using C libraries? My version is only 4K, whats the size of your version? Come on now, that's not the asm way to do things buddy!
I am not going on your litlle church (memfree) ,but on a way to use the CRT with masm and to display values easily.

Bill Cravener

Don't take my comments to heart Tout, I'm just ribbing you (ribbing means joking or kidding between friends). :bg
My MASM32 Examples.

"Prejudice does not arise from low intelligence it arises from conservative ideals to which people of low intelligence are drawn." ~ Isaidthat