View Full Version : Mac memory status functions?
Puzzler183
2005.05.01, 01:40 AM
Right now, I have a routine to get system information. Part of that routine is below - it finds how much physical memory your system has. The catch is I'd like to actually implement it for Macs but I can't since I can't find the equivalent functions for Macs. The only thing I found was FreeMem in MacMemory.h but I'm not sure if that's what I want and it would only solve half of my problem.
#if defined(WIN32)
MEMORYSTATUS memoryStatus;
GlobalMemoryStatus(&memoryStatus);
systemInfo.availableRAM = memoryStatus.dwAvailPhys / 1048576;
systemInfo.totalRAM = memoryStatus.dwTotalPhys / 1048576;
LOG("avail: %d total: %d", systemInfo.availableRAM, systemInfo.totalRAM);
#elif defined(macintosh)
systemInfo.availableRAM = -1;
systemInfo.totalRAM = -1;
#else
systemInfo.availableRAM = -1;
systemInfo.totalRAM = -1;
#endif
So, is FreeMem what I'm looking for or what is the Mac equivalent of that code?
OneSadCookie
2005.05.01, 04:31 AM
sysctl can tell you the total physical memory (man 1 sysctl, man 3 sysctl). For anything else, the source to top is in the Darwin CVS. I suggest you take a look there.
Fenris
2005.05.01, 07:45 AM
Keith, what's wrong with Gestalt?
SInt32 physicalRAMSize;
Gestalt (gestaltPhysicalRAMSize, &physicalRAMSize);
Puzzler183
2005.05.01, 12:04 PM
Ok, thanks, I'll look into those:).
arekkusu
2005.05.01, 12:38 PM
SInt32 is not big enough for G5's, that's what's wrong with Gestalt ;)
Fenris
2005.05.01, 01:36 PM
Arekkusu, does that mean that it WILL break on a G5, or break if the G5 has too much memory available?
OneSadCookie
2005.05.01, 05:11 PM
sysctl is the new old Gestalt :)
Puzzler183
2005.05.01, 05:26 PM
Ok, so if you could just look at this code to make sure I have the right idea with the Gestalt thing... I wasn't sure what OSErr would return upon failure so I just assumed it would be -1 - I need someone to tell me what it actually is though. Anyway, the new code is below.
#if defined(WIN32)
MEMORYSTATUS memoryStatus;
GlobalMemoryStatus(&memoryStatus);
systemInfo.availableRAM = memoryStatus.dwAvailPhys / 1048576;
systemInfo.totalRAM = memoryStatus.dwTotalPhys / 1048576;
#elif defined(macintosh)
systemInfo.availableRAM = -1;
if(Gestalt(gestaltPhysicalRAMSize, systemInfo.totalRAM) < 0)
systemInfo.totalRAM = -1;
else
systemInfo.totalRAM /= 1048576;
#else
systemInfo.availableRAM = -1;
systemInfo.totalRAM = -1;
#endif
Puzzler183
2005.05.01, 05:36 PM
Actually, better yet, I added a few more things (that right now are Mac only) with this Gestalt. Assuming I understood it right, any chance I could get someone to compile this, just to make sure my syntax is right? I also looked at sample code and found the noErr value so now I check against that.
//Updates the system information
void core::Engine::updateSystemInfo()
{
//CPU
#if defined(macintosh)
if(Gestalt(gestaltProcClkSpeed, systemInfo.CPU.clockSpeed) != noErr)
systemInfo.CPU.clockSpeed = -1;
#else
systemInfo.CPU.clockSpeed = -1;
#endif
systemInfo.CPU.hasRDTSC = SDL_HasRDTSC();
systemInfo.CPU.hasMMX = SDL_HasMMX();
systemInfo.CPU.hasMMXExt = SDL_HasMMXExt();
systemInfo.CPU.hasSSE = SDL_HasSSE();
systemInfo.CPU.hasSSE2 = SDL_HasSSE2();
systemInfo.CPU.has3DNow = SDL_Has3DNow();
systemInfo.CPU.has3DNowExt = SDL_Has3DNowExt();
systemInfo.CPU.hasAltiVec = SDL_HasAltiVec();
//Bus clock speed
#if defined(macintosh)
if(Gestalt(gestaltBusClkSpeed, systemInfo.busClockSpeed) != noErr)
systemInfo.busClockSpeed = -1;
#else
systemInfo.busClockSpeed = -1;
#endif
//RAM
#if defined(WIN32)
MEMORYSTATUS memoryStatus;
GlobalMemoryStatus(&memoryStatus);
systemInfo.RAM.available = memoryStatus.dwAvailPhys / 1048576;
systemInfo.RAM.total = memoryStatus.dwTotalPhys / 1048576;
#elif defined(macintosh)
systemInfo.RAM.available = -1;
if(Gestalt(gestaltPhysicalRAMSize, systemInfo.RAM.total) == noErr)
systemInfo.RAM.total /= 1048576;
else
systemInfo.RAM.total = -1;
#else
systemInfo.RAM.available = -1;
systemInfo.RAM.total = -1;
#endif
}
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.