Mac memory status functions?

Puzzler183
Unregistered
 
Post: #1
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.

Code:
#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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #3
Keith, what's wrong with Gestalt?
Code:
SInt32 physicalRAMSize;
Gestalt (gestaltPhysicalRAMSize, &physicalRAMSize);
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #4
Ok, thanks, I'll look into thoseSmile.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #5
SInt32 is not big enough for G5's, that's what's wrong with Gestalt Wink
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #6
Arekkusu, does that mean that it WILL break on a G5, or break if the G5 has too much memory available?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
sysctl is the new old Gestalt Smile
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #8
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.

Code:
#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
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #9
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.

Code:
//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
}
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  virtual functions not working supersonic 2 4,928 Mar 10, 2011 06:22 AM
Last Post: compiler
  exporting c functions and variables NelsonMandella 6 4,880 Apr 1, 2010 05:07 PM
Last Post: NelsonMandella
  Haskell Data Types and Functions wyrmmage 1 3,391 Mar 4, 2008 05:25 PM
Last Post: OneSadCookie
  Virtual functions/Inheritance. BinarySpike 5 4,227 Sep 29, 2005 11:16 AM
Last Post: BinarySpike