The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: ToutEnMasm on November 01, 2011, 06:54:21 AM

Title: Meminfo
Post by: ToutEnMasm on November 01, 2011, 06:54:21 AM

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.
Title: Re: Meminfo
Post by: dedndave on November 01, 2011, 07:09:10 AM
XP MCE2005 SP3 - prescott w/htt - 1Gb RAM
MessageBox font/size: Tahoma 10 (SystemParametersInfo, NONCLIENTMETRICS.lfMessageFont)

(http://www.masm32.com/board/index.php?action=dlattach;topic=17655.0;id=9900)

"dwMemoryLoad Percent memory in used"

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

or...
"dwMemoryLoad Percent memory used"
Title: Re: Meminfo
Post by: ToutEnMasm on November 01, 2011, 10:05:32 AM

Wich is the compressor you use . png.zip ? not recognize by 7.zip
Title: Re: Meminfo
Post by: fearless on November 01, 2011, 01:49:07 PM
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]
Title: Re: Meminfo
Post by: Bill Cravener on November 01, 2011, 01:51:35 PM
 :bg

http://www.quickersoft.com/examples/MemFree.zip
Title: Re: Meminfo
Post by: ToutEnMasm on November 01, 2011, 02:07:50 PM
miss the units (it's rounded to thousand ) and the % of memory in use.
:dance:
Title: Re: Meminfo
Post by: clive on November 01, 2011, 02:56:31 PM
(http://www.masm32.com/board/index.php?action=dlattach;topic=17655.0;id=9902)
Title: Re: Meminfo
Post by: ToutEnMasm on November 01, 2011, 03:34:22 PM

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 ...

Title: Re: Meminfo
Post by: dedndave on November 01, 2011, 03:59:15 PM
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
Title: Re: Meminfo
Post by: ToutEnMasm on November 01, 2011, 04:15:38 PM

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
Title: Re: Meminfo
Post by: Bill Cravener on November 01, 2011, 04:45:16 PM
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

Title: Re: Meminfo
Post by: clive on November 01, 2011, 05:09:21 PM
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.
Title: Re: Meminfo
Post by: jj2007 on November 01, 2011, 05:32:20 PM
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)
Title: Re: Meminfo
Post by: ToutEnMasm on November 01, 2011, 07:04:54 PM

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.
Title: Re: Meminfo
Post by: Bill Cravener on November 01, 2011, 07:51:16 PM
Don't take my comments to heart Tout, I'm just ribbing you (ribbing means joking or kidding between friends). :bg
Title: Re: Meminfo
Post by: ToutEnMasm on November 02, 2011, 09:50:47 AM

I know that i could play a little with bill.
If it is only a question of size,this one is only 2.5k
It's just for play.
:bg
Title: Re: Meminfo
Post by: Bill Cravener on November 02, 2011, 02:10:43 PM
Tout, now that's more like it. :bg

So how did you make your mem example so small??
Title: Re: Meminfo
Post by: dedndave on November 02, 2011, 03:28:26 PM
works well, Yves    :U

that shows you one big advantage for writing in asm as opposed to writing in C
a lot of C programmers are surprised by how small a program can be   :P
Title: Re: Meminfo
Post by: ToutEnMasm on November 02, 2011, 04:33:07 PM

Thanks for encouragements.
source code is here.
http://www.masm32.com/board/index.php?topic=17664.msg148822#msg148822
How did i made it so smalll ?
_ first a good size for the buffer , only 100 bytes free with a normal computer (could be decrease)
_ second the use of my code to format the string
_ last,the help of polink to finish the work.
Title: Re: Meminfo
Post by: Antariy on November 25, 2011, 08:31:50 PM
Quote from: clive on November 01, 2011, 05:09:21 PM
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.

MemInfoMicro (http://www.masm32.com/board/index.php?topic=15159.0) has units which are dynamically changing, depend on value of number :bg