Free and Total Memory C ++

1

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
source

1 answer

3

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()
{
    MEMORYSTATUSEX status;
    status.dwLength = sizeof(status);
    GlobalMemoryStatusEx(&status);
    return status.ullTotalPhys;
}

Question brought from SO

    
answered by 23.05.2017 в 14:39