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.
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"
Wich is the compressor you use . png.zip ? not recognize by 7.zip
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]
:bg
http://www.quickersoft.com/examples/MemFree.zip
miss the units (it's rounded to thousand ) and the % of memory in use.
:dance:
(http://www.masm32.com/board/index.php?action=dlattach;topic=17655.0;id=9902)
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 ...
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
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
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
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.
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)
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.
Don't take my comments to heart Tout, I'm just ribbing you (ribbing means joking or kidding between friends). :bg
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
Tout, now that's more like it. :bg
So how did you make your mem example so small??
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
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.
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