Qt获取内存信息

原文地址:https://blog.csdn.net/Joker__123/article/details/125064795

    int MB = 1024 * 1024;     
    MEMORYSTATUSEX memoryStateEx;
    memoryStateEx.dwLength = sizeof(memoryStateEx);   //这句忘记写导致出错!!!
    GlobalMemoryStatusEx(&memoryStateEx);
    int useMenoryPercent = memoryStateEx.dwMemoryLoad;
    int allMemory = memoryStateEx.ullTotalPhys / MB;
    int freeMemory = memoryStateEx.ullAvailPhys / MB;
    int useMemory = allMemory - freeMemory;
    qDebug() << QStringLiteral("物理内存的使用率:") << useMenoryPercent << "%";
    qDebug() << QStringLiteral("总的物理内存:") << allMemory << "MB";
    qDebug() << QStringLiteral("剩余物理内存:") << freeMemory << "MB";
    qDebug() << QStringLiteral("已经使用的物理内存:") << useMemory << "MB";
    qDebug() << QStringLiteral("系统页面总大小:") << memoryStateEx.ullTotalPageFile / MB << "MB";
    qDebug() << QStringLiteral("系统可用页面大小:") << memoryStateEx.ullAvailPageFile / MB << "MB";
    qDebug() << QStringLiteral("虚拟内存总量:") << memoryStateEx.ullTotalVirtual / MB << "MB";
    qDebug() << QStringLiteral("虚拟内存那时可使用大小:") << memoryStateEx.ullAvailVirtual / MB << "MB";
    qDebug() << QStringLiteral("结构体保留值(固定为0):") << memoryStateEx.ullAvailExtendedVirtual;

 

posted @ 2023-01-09 09:24  远方是什么样子  阅读(250)  评论(0编辑  收藏  举报