1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 11:32:42 +01:00
ScreenPlay/ScreenPlaySysInfo/ram.cpp

35 lines
1019 B
C++
Raw Normal View History

2018-10-26 12:05:23 +02:00
#include "ram.h"
2020-10-29 19:17:37 +01:00
#include "sysinfoapi.h"
2018-10-26 12:05:23 +02:00
#include <QtQml/qqml.h>
#include <qmetatype.h>
2018-12-02 21:22:12 +01:00
2018-10-26 12:05:23 +02:00
RAM::RAM(QObject* parent)
: QObject(parent)
{
2020-10-29 19:17:37 +01:00
connect(&m_updateTimer, &QTimer::timeout, this, &RAM::update);
2018-12-02 21:22:12 +01:00
m_updateTimer.start(m_tickRate);
}
void RAM::update()
{
//Get values from system
MEMORYSTATUSEX memoryStatus;
memoryStatus.dwLength = sizeof(MEMORYSTATUSEX); //needed for internal api
bool success = GlobalMemoryStatusEx(&memoryStatus);
2020-10-29 19:17:37 +01:00
if (!success)
2018-12-02 21:22:12 +01:00
return;
//Apply total values
setTotalPhysicalMemory(memoryStatus.ullTotalPhys);
setTotalPagingMemory(memoryStatus.ullTotalPageFile);
setTotalVirtualMemory(memoryStatus.ullTotalVirtual);
//calculate usages
setUsedPhysicalMemory(m_totalPhysicalMemory - memoryStatus.ullAvailPhys);
setUsedPagingMemory(m_totalPagingMemory - memoryStatus.ullAvailPageFile);
setUsedVirtualMemory(m_totalVirtualMemory - memoryStatus.ullAvailVirtual);
2018-10-26 12:05:23 +02:00
2018-12-02 21:22:12 +01:00
//set overall usage
setUsage(memoryStatus.dwMemoryLoad);
2018-10-26 12:05:23 +02:00
}