Free and Total Memory C ++


I am looking for a function to be able to review the total memory and the free memory from DevC ++, applicable in an object-oriented code and that can be used in a class for structures such as Listas and Arboles .

If the question is very long or has many answers, I would be very grateful if you would tell me a book or another place where I can consult such information.

asked by Amiguito del bosque 28.02.2017 в 06:36

1 answer


Original response from Travis Gockel

You can use sysconf on Unix-like systems.

#include <unistd.h>

unsigned long long getTotalSystemMemory()
    long pages = sysconf(_SC_PHYS_PAGES);
    long page_size = sysconf(_SC_PAGE_SIZE);
    return pages * page_size;

For windows-based systems GlobalMemoryStatusEx :

#include <windows.h>

unsigned long long getTotalSystemMemory()
    status.dwLength = sizeof(status);
    return status.ullTotalPhys;

Question brought from SO

answered by 23.05.2017 в 14:39