03-10-2010 01:50 PM
(This is under Windows OS)
I am making a benchmarking program to get statistics on performance for some complicated calculations based on computer hardware.
What is the best way to obtain the amount of installed RAM programmatically?
How do I tell if the OS is 32 or 64 bit?
Thanks!
Solved! Go to Solution.
03-10-2010 02:00 PM - edited 03-10-2010 02:07 PM
does a call to the getnativesysteminfo function in kernel32.dll give it to you?
Here are some details. You can also try the IsWow64Process function, but I don't believe that is exactly what you want. As for the Ram, not sure.
03-10-2010 02:53 PM
vi.lib\platform\system.llb has memstats.vi
vi.lib\utility\sysinfo.llb has Get Current platform
also look at property node >>> application >>> target stuff
Ben
03-10-2010 03:35 PM - edited 03-10-2010 03:36 PM
Ben, it doesn't look like the Memstats VI returns the installed memory. It returns a number, but I can't match it to the amount of memory installed in my system. The GetCurrentPlatform seems to only return the OS Name, not whether it's 32-bit or 64-bit. I didn't see anything in the App->Target list that contained this information. At least in 8.2. Haven't checked in 2009.
altenbach wrote:(This is under Windows OS)
I am making a benchmarking program to get statistics on performance for some complicated calculations based on computer hardware.
What is the best way to obtain the amount of installed RAM programmatically?
How do I tell if the OS is 32 or 64 bit?
Thanks!
Define "best". Best in speed? Best in compatibility over multiple versions of the Windows OS? Best in terms of accessing this information without having to delve too much into all sorts of Windows datatypes and DLLs?
Would you consider .NET to be a candidate for "best". If so, the amount of installed RAM can be easily acquired using the Microsoft.VisualBasic.Devices.ComputerInfo class:
As for determining whether your OS is 32-bit or 64-bit are you trying to distinguish between a 32-bit OS on a 64-bit CPU vs a 64-bit OS on a 64-bit CPU? I know the WMI class can be used to get this information, so if you're trying to make that distinction you could look at the Win32_ComputerSystem and Win32_Processor classes. For instance, I believe the following is what you would see:
64bit OS on x64processor:
win32_computersystem.systemtype = x64-based pc
win32_processor.addresswidth = 64
win32_processor.architecture = 9
win32_processor.datawidth = 64
32bit OS on x86processor:
win32_computersystem.systemtype = x86-based pc
win32_processor.addresswidth = 32
win32_processor.architecture = 0
win32_processor.datawidth = 32
32bit OS on x64processor:
win32_computersystem.systemtype = x86-based pc
win32_processor.addresswidth = 32
win32_processor.architecture = 9
win32_processor.DataWidth = 64
I've attached an example on how to access the classes with .NET. Not pretty, but not overly ugly either.
03-10-2010 03:45 PM - edited 03-10-2010 03:46 PM
smercurio_fc wrote:Define "best".
Just a quick and dirty method that does not require advanced knowledge of the windows guts, works on all OS variations, and does not require fancy code. 😉 (All I want is everything!)
I thougth maybe I could read the RAM out of the registry (That's what I do for the CPU info at the moment, see image), but I have not found the key.
Here's what I whipped up last night, maybe it's all wrong. I have not tried it on different machines.
Thanks for all the suggestions, I'll study them tonight. 😄
03-10-2010 04:10 PM
altenbach wrote:
smercurio_fc wrote:Define "best".
Just a quick and dirty method that does not require advanced knowledge of the windows guts, works on all OS variations, and does not require fancy code. 😉 (All I want is everything!)
I thougth maybe I could read the RAM out of the registry (That's what I do for the CPU info at the moment, see image), but I have not found the key.
There's an HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory\.Translated (yes, that's a period there). It's a packed value. Not sure how to unpack this value.
03-10-2010 04:27 PM
I am a bit old-fashioned when it comes to getting the RAM.
Not a lot of useful info returned, but it does give the total installed RAM.
03-10-2010 04:37 PM
Darin.K wrote:I am a bit old-fashioned when it comes to getting the RAM.
Not a lot of useful info returned, but it does give the total installed RAM.
I had already tried that. It doesn't return anything remotely close to the total installed RAM. That returns the total contiguous extended memory, which isn't the same as the total installed RAM.
03-10-2010 04:57 PM
Should have looked more closely at the number. That is what I get for trying to dust off a command I probably last used on Windows 95. Now that DOS is off in its own land it is harder to get that info. There is probably a way to tie into Msinfo32, but that probably reads the Registry.
03-10-2010 04:59 PM