Hi. Does anyone know how to
A) Check the CPU speed
B) Detect RAM
C) Detect video card memory
All without using DirectX (I use MinGW)?
Detecting hardware
-
Guest
This should get you A and B. Should work on Linux and Windows both. Havent' fully tested them though.
Code: Select all
bool getProcessorSpeedMHz(irr::u32* MHz)
{
#if defined(_IRR_WINDOWS_)
LONG Error;
HKEY Key;
Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
0, KEY_READ, &Key);
if(Error != ERROR_SUCCESS)
return false;
DWORD Speed = 0;
DWORD Size = sizeof(Speed);
Error = RegQueryValueEx(Key, "~MHz", NULL, NULL, (LPBYTE)&Speed, &Size);
RegCloseKey(Key);
if (Error != ERROR_SUCCESS)
return false;
else if (MHz)
*MHz = Speed;
return true;
#elif defined(LINUX)
// could probably read from "/proc/cpuinfo" or "/proc/cpufreq" also
struct clockinfo CpuClock;
size_t Size = sizeof(clockinfo);
if (!sysctlbyname("kern.clockrate", 2, &CpuClock, &Size, NULL, 0))
return false;
else if (MHz)
*MHz = CpuClock.hz;
return true;
#else
return false;
#endif
}
bool getSystemMemory(irr::u32* Total, irr::u32* Avail)
{
#if defined(_IRR_WINDOWS_)
MEMORYSTATUS MemoryStatus;
MemoryStatus.dwLength = sizeof(MEMORYSTATUS);
// cannot fail
GlobalMemoryStatus(&MemoryStatus);
if (Total)
*Total = (irr::u32)MemoryStatus.dwTotalPhys;
if (Avail)
*Avail = (irr::u32)MemoryStatus.dwAvailPhys;
return true;
#elif defined(LINUX)
// could probably read from "/proc/meminfo"
struct sysinfo SystemStatus;
if (!sysinfo(&SystemStatus))
return false;
if (Total)
*Total = SystemStatus.totalram;
if (Avail)
*Avail = SystemStatus.freeram;
return true;
#else
return false;
#endif
}
-
Anteater