TotalPhysicalMemory

whittler

New member
Joined
Jun 4, 2007
Messages
3
Programming Experience
Beginner
Hi There,

The Property My.Computer.Info.TotalPhysicalMemory seems to be a bit off. My physical RAM is 768Mb, whereas that Property returns 804Mb. I have confirmed this gap on two other boxes as well.

Soooo, I have used an expression to calculate the amount of RAM in use:
VB.NET:
Me.lblRAM.Text = Math.Round((My.Computer.Info.TotalPhysicalMemory - _
            My.Computer.Info.AvailablePhysicalMemory) / 1000000).ToString() & " Mb"

In light of the discrepancy above, will my calculation be correct, or should it be more along the lines of (pseudocode):
VB.NET:
RAM Used = 768 - available physical memory

Thanks
 
The property returns the correct value. You're system has 768 binary megabytes of RAM. A binary megabyte is 1024 binary kilobytes, which is 1024 binary bytes. 1024 is equal to 2^10. You are calculating the number of decimal megabytes. Both are completely legitimate measures but it's best to know which you're dealing with. For instance, some people get stroppy because they buy a hard disk that has so many gigabytes of space and then find that it's smaller than they thought when they look at it through Windows. That's because Windows reports binary gigabytes while drive manufacturers report decimal gigabytes. If you want to split hairs the decimal system should be the "official" system but the binary system is much more convenient when dealing with computers.
 
Thanks jmcilhinney,

I am still having a bit of trouble with the Maths. I have 3 numbers - 804Mb, 768Mb and 1024Mb and I cannot get them to marry up.

It's not a biggie, but I do like to understand such things.

Thanks
 
TotalPhysicalMemory contains the number of bytes of memory your computer has. Divide it by 1024 to get the number of kilobytes and by 1024 again to get the number of megabytes. You were mistakenly using a factor of 1000*1000 instead of 1024*1024.
 
Last edited:
Tops. That has it totally sorted.

Here's the sum:
804233216 / 1024 / 1024 = 766.9

I have a Widget on my desktop which tells me that my RAM is 766.9MB (rather than 768MB).

So all the numbers work out.

Thanks very much for that.
 
Back
Top