0

Is there an easy way to find out how much RAM (in MB) does my program use after different operations (large matrix manipulation)? I am using Windows 10.

mathys
  • 51
  • 5

1 Answers1

1

The C++ standard (read e.g. n3337) don't mention RAM, so your question is operating system specific. Also, on most OSes a process runs in virtual memory, and two different processes might share some common (either virtual, or physical) memory. Read a good textbook on operating systems.

During execution, some pages might be swapped out to the swap area on your disk.

Hence, the very notion of RAM usage is approximate and changes with time. Read about thrashing and page faults and MMU.

But on Linux, you could use the /proc/ file system. Read proc(5) . Your program would access /proc/self/maps

For Windows, read the WinAPI documentation. You probably want virtual memory functions and memory management functions.

You might redefine your ::operator new and/or use libraries like POCO. With GPGPUs and OpenCL things become even more complex. Some compilers have OpenACC extensions facilitating these.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547