1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-09 12:32:40 +01:00
ScreenPlay/ScreenPlaySysInfo/ram.cpp
2018-12-02 21:22:12 +01:00

35 lines
1015 B
C++

#include "ram.h"
#include <QtQml/qqml.h>
#include <qmetatype.h>
#include "sysinfoapi.h"
RAM::RAM(QObject* parent)
: QObject(parent)
{
connect(&m_updateTimer,&QTimer::timeout,this,&RAM::update);
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);
if(!success)
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);
//set overall usage
setUsage(memoryStatus.dwMemoryLoad);
}