Getting memory information with Qt



  • 2 Answer(s)

    Memory information with Qt:

    They developed by using the given code and make the  error point  in the write control. The values are  possible in the  present the  perhaps memory is used at the present application

    Windows GlobalMemoryStatusEx

    MEMORYSTATUSEX memory_status;
    ZeroMemory(&memory_status, sizeof(MEMORYSTATUSEX));
    memory_status.dwLength = sizeof(MEMORYSTATUSEX);
    if (GlobalMemoryStatusEx(&memory_status)) {
        system_info.append(
            QString("RAM: %1 MB")
            .arg(memory_status.ullTotalPhys / (1024 * 1024)));
    } else {
      system_info.append("Unknown RAM");
    }
    

    Linux proc/meminfo

    QProcess p;
    p.start("awk", QStringList() << "/MemTotal/ { print $2 }" << "/proc/meminfo");
    p.waitForFinished();
    QString memory = p.readAllStandardOutput();
    system_info.append(QString("; RAM: %1 MB").arg(memory.toLong() / 1024));
    p.close();
    

    Mac sysctl

    QProcess p;
    p.start("sysctl", QStringList() << "kern.version" << "hw.physmem");
    p.waitForFinished();
    QString system_info = p.readAllStandardOutput();
    p.close();
    
    Answered on December 27, 2018.
    Add Comment

    The  POSIX OSes Linux, Solaris, perhaps latest MacOS:

    • getrusage(…) secially look at ru_maxrss.
    • getrlimit(…) but I did not find any usefull info into.
    • sysconf(…) : _SC_PAGESIZE, _SC_PHYS_PAGES, _SC_AVPHYS_PAGES
    • sysinfo(…) : totalram, freeram, sharedram, totalswap,…

    The cache  on POSIX computers are not accesible on Windows.

    Answered on December 27, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.