How much ram the computer is using etc.

How can I check things like how much ram the computer system is using in total currently (not just for the program), how much space is in drive and how much ram the computer is capable of?
What operating system are you using?

Windows task manager will tell you the amount of memory in use. In windows explorer, right-clicking on a drive and looking at its properties will tell you how much free space it has. Identify your motherboard and read the specs on the manufacturers website to see the maximum amount of RAM you can put in it.
I want my program to know have that information about the user. Sorry that I was vague. And when I meant capable RAM I meant total RAM :P

I appreciate it though that you tried to help me with that.

How can I collect such information? Those were examples
Last edited on
Well...
- there's the physical RAM on your motherboard(*).
- minus the part reserved for on-board graphics (if present), either by the BIOS or the OS ( https://en.wikipedia.org/wiki/Graphics_processing_unit#Integrated_graphics )
- minus the part for specific hardware requirements( https://support.microsoft.com/en-gb/help/978610/the-usable-memory-may-be-less-than-the-installed-memory-on-windows-7-b )
- minus the part reserved for OS use only.

What remains is available to use by user-land processes, but not directly!
On a modern OS like Windows, Linux, MacOS, the memory seen by any user-space program is virtual memory.

So whilst you may have done int *large = new int[10000000];, your program isn't instantly the exclusive owner of another 50MB of RAM. It's the owner of 50MB of it's own virtual address space.

It's only when you try to use the memory that the OS will physically map real RAM to your process.
https://docs.microsoft.com/en-us/windows/desktop/memory/working-set
The working set (the memory dedicated to your process at one particular moment) is a very fluid thing, depending on what your program is doing and the overall load on the system).

So, what are you trying to measure?

(*) and if you're booting into a virtual machine like VMWare or VirtualBox, then even that is a smoke and mirrors value.
Windows:
GlobalMemoryStatusEx : https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-globalmemorystatusex
GetDiskFreeSpaceExA : https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getdiskfreespaceexa

Linux:
sysinfo (2) : https://linux.die.net/man/2/sysinfo
statvfs (2) : https://linux.die.net/man/2/statvfs

C++ wrapper around system call for file system statistics: https://en.cppreference.com/w/cpp/filesystem/space

Note that POSIX makes no guarantees about the correctness of the information returned by statvfs.
do you want this inside your program or for your own information?
Its a bit harder inside a program. For your own knowledge, you can get it from the OS as said. I use cygwin, so I can use the unix commands like df on my windows box... windows dir command has disk free... ram is more tricky, but tasklist /fi "memusage gt 0" or systeminfo will give you that info on windows.
Last edited on
Topic archived. No new replies allowed.