Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get RAM system size

I would like to know how can I get the size of my RAM through C++ (on Windows 7).

like image 696
Octopus Avatar asked Apr 05 '11 14:04

Octopus


People also ask

How do I check my RAM size?

Here's how: Press Ctrl + Shift + Esc to launch Task Manager. Or, right-click the Taskbar and select Task Manager. Select the Performance tab to see current RAM usage displayed in the Memory box, and total RAM capacity listed under Physical Memory.

How can I check RAM size in CMD?

Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to determine the total amount of RAM installed on the computer and press Enter: wmic computersystem get totalphysicalmemory.

How many GB is my RAM Linux?

Checking memory size in GB in Linux Open the Linux terminal application. Press the enter key. The -g option show output in GB (gibibytes) for Linux memory. To get human-readable output you need to pass the -h option.


1 Answers

Use GetPhysicallyInstalledSystemMemory to retrieve the amount of RAM that is physically installed on the computer.

(Note that this requires Windows Vista SP1 or later. The function is not available on earlier versions of the Windows operating system.)

The remarks on MSDN say:

The GetPhysicallyInstalledSystemMemory function retrieves the amount of physically installed RAM from the computer's SMBIOS firmware tables. This can differ from the amount reported by the GlobalMemoryStatusEx function, which sets the ullTotalPhys member of the MEMORYSTATUSEX structure to the amount of physical memory that is available for the operating system to use. The amount of memory available to the operating system can be less than the amount of memory physically installed in the computer because the BIOS and some drivers may reserve memory as I/O regions for memory-mapped devices, making the memory unavailable to the operating system and applications.

The amount of physical memory retrieved by the GetPhysicallyInstalledSystemMemory function must be equal to or greater than the amount reported by the GlobalMemoryStatusEx function; if it is less, the SMBIOS data is malformed and the function fails with ERROR_INVALID_DATA. Malformed SMBIOS data may indicate a problem with the user's computer.

That means, you would also want to look at GlobalMemoryStatusEx.

like image 103
Nawaz Avatar answered Sep 26 '22 08:09

Nawaz