News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Total System RAM Estimation

Started by dedndave, October 26, 2015, 04:21:53 AM

Previous topic - Next topic

dedndave

on this one, i am using GlobalMemoryEx to get memory information
the MEMORYSTATUSEX structure returns a "ullTotalPhys" value
but, it's never quite what you really have
(BIOS, OS, and/or software reserves some RAM, leaving the value a little short)

so, i am trying to estimate the actual total physical memory....

           MemoryLoad =          0000001Dh = 29
          GuessedPhys = 00000000_80000000h = 2147483648
            TotalPhys = 00000000_7F6BA000h = 2137759744
            AvailPhys = 00000000_5A191000h = 1511591936
        TotalPageFile = 00000000_D5193000h = 3575197696
        AvailPageFile = 00000000_B8DEA000h = 3101597696
         TotalVirtual = 00000000_7FFE0000h = 2147352576
         AvailVirtual = 00000000_7F9E2000h = 2141069312
AvailExtendedVirtual = 00000000_00000000h = 0



Vortex

Hi Dave,

Nice work. A small suggestion, could you convert the byte values to megabyte? It's easier to follow and read MB values.

My test result :


           MemoryLoad =          00000023h = 35
          GuessedPhys = 00000000_80000000h = 2147483648
            TotalPhys = 00000000_7FEBB000h = 2146152448
            AvailPhys = 00000000_5257B000h = 1381478400
        TotalPageFile = 00000000_D65C6000h = 3596378112
        AvailPageFile = 00000000_926D8000h = 2456649728
         TotalVirtual = 00000000_7FFE0000h = 2147352576
         AvailVirtual = 00000000_7F9A8000h = 2140831744
AvailExtendedVirtual = 00000000_00000000h = 0

dedndave

thanks Erol
i plan on doing that - but i wanted to test this little algo on different machines to see if it's ok   :P

i guess i could just run a bunch of numbers through it - lol

TouEnMasm


This one is very well known on the forum,search for short memory info
Work with Windows 10
Fa is a musical note to play with CL

Siekmanski

Windows 8.1


           MemoryLoad =          00000010h = 16
          GuessedPhys = 00000004_00000000h = 17179869184
            TotalPhys = 00000003_FC55E000h = 17118388224
            AvailPhys = 00000003_57253000h = 14346956800
        TotalPageFile = 00000004_9455E000h = 19668525056
        AvailPageFile = 00000003_D9B7A000h = 16537591808
         TotalVirtual = 00000000_7FFE0000h = 2147352576
         AvailVirtual = 00000000_7F5E2000h = 2136875008
AvailExtendedVirtual = 00000000_00000000h = 0

Press any key to continue ...
Creative coders use backward thinking techniques as a strategy.

Zen

#5
Hi, DAVE,
Windows Seven Professional

          MemoryLoad =          00000032h = 50
          GuessedPhys = 00000000_80000000h = 2147483648
          TotalPhys = 00000000_7F4F8000h       = 2135916544
          AvailPhys = 00000000_3E755000h       = 1047875584
          TotalPageFile = 00000000_FE9F0000h  = 4271833088
          AvailPageFile = 00000000_ACE8B000h = 2900930560
          TotalVirtual = 00000000_7FFE0000h    = 2147352576
          AvailVirtual = 00000000_7F473000h    = 2135371776

...I'm wondering exactly what we're talking about here,...
I was playing around with WbemTest (on my computer, it is located at: C:\Windows\System32\wbem\wbemtest.exe), and trying to find a WMI class that was comparable in terms of capacity with the data that your app is producing.
See: Computer System Hardware Classes, MSDN
My two best guesses are: Win32_PhysicalMemory Class, MSDN, and, Win32_MemoryDevice Class, MSDN
When I examine the instances of both classes, there is very little useful information available. But, the instances of the Win32_PhysicalMemory Class (there are two), identify the attribute: MemoryType as DDR2. It's capacity is: 1073741824 bytes (fairly close to, AvailPhys). 

dedndave

it isn't rocket science - lol

as you know, the value reported by GlobalMemoryStatusEx is always just a little bit short of actual

values like 2 MB, 4 MB, 1 GB, 2 GB, 4 GB all have one thing in common
they have a single bit set - all other bits are 0's

well, we want to accomodate the oddball cases: 3GB, 1.5 GB, etc
these all have 2 adjacent bits set

going one step further, values like 7GB seem possible, in rare cases
3 adjacent bits set

so - the algo finds the highest bit, and rounds up so that only the upper 3 bits may be set
at least, that's the idea behind it - i am going to have to re-visit this and verify my algo is correct

Zen

...Ha,...Ha,...:bgrin:
I just found it a bit confusing,...
...But, seriously,...you have loyal fans here,...you could just throw in a Device Context,...and, we'd all be happy as hell,...:bgrin:

Zen

Hi, DAVE, again,
You might find this SysInternals Utility interesting: RAMMap v1.4, By Mark Russinovich.
...RAMMap has to run elevated, because 'it goes deep into the kernel',...
...As I recall,...you are still running on Windows XP (SO RETRO !!!),...RAM Map only works on Windows Vista and higher,...:bgrin:

...There is, however, an excellent video that explains how RAMMap works: Defrag Tools: #6 - RAMMap, Channel 9, 2012.
...This video is over 30 minutes long, but, VERY informative,...

...By the way, when I run RAMMap, it shows that I have 2,085,856 KB of Total RAM Memory,...
...You might find this interesting: Working Set, MSDN

TWell

#9
Something here too
Keywords are Win32 API GetSystemFirmwareTable() and smbios

dedndave

i suppose the WMI method might be best
it's probably where the System (My Computer) Properties sheet gets the value

dedndave


dedndave

2 tough ones left: OS and CPU identification (oh - and an easy one to display the hardware strings)
i've got a good start on both of those, too   :biggrin:


Grincheux

What is the difference with GetPhysicallyInstalledSystemMemory

QuoteBOOL WINAPI GetPhysicallyInstalledSystemMemory(_Out_ PULONGLONG TotalMemoryInKilobytes);

Parameters
TotalMemoryInKilobytes [out]
A pointer to a variable that receives the amount of physically installed RAM, in kilobytes.

Return value

If the function succeeds, it returns TRUE and sets the TotalMemoryInKilobytes parameter to a nonzero value.
If the function fails, it returns FALSE and does not modify the TotalMemoryInKilobytes parameter. To get extended error information, use the GetLastError function. Common errors are listed in the following table.



dedndave

that may be a good method but, according to MSDN, it requires Vista +SP1 or newer
i prefer a function that works on older OS's, is all
i have kind of given up trying to support win95, or even win98
but, it's nice if it works on win2000 and newer