Game Development Community

TGEA 1.8.1 Mac Processor and RAM not correctly determined

by Andrew13 · in Torque Game Engine Advanced · 03/16/2009 (4:00 pm) · 4 replies

On a Mac with 10.5.6 where processor is 2.33 Core 2 Duo and RAM is 3GB the console reports

Physical RAM: 2047MB
Logical RAM: 2047MB
Unknown Getstalt value for processor type: 0x69353836
platform layer should be changed to use sysctl() instead of Gestalt() .
Unknown Processor, assuming x86 Compatible, 2147 Mhz

On a second test machine (10.5.6) where processor is Dual Xeon and 8 GB ram the console reports

Physical RAM: 2047MB
Logical RAM: 2047MB
Unknown Getstalt value for processor type: 0x69353836
platform layer should be changed to use sysctl() instead of Gestalt() .
Unknown Processor, assuming x86 Compatible, 2147 Mhz

#1
06/27/2009 (12:50 am)
Eh, I know this is old news by now but I posted a SYSCTL-savvy version back around the start of the year. (This is what happens when I get swamped and stop poking around for a while.)

http://www.garagegames.com/community/forums/viewthread/81815

There's no telling how little use any of this information actually is but if nothing else, the routine posted there can certainly show you how to get at the flags properly.
#2
06/28/2009 (4:52 pm)
@Andrew13
OSX is pretty peculiar here. I found that if one updates the code in question here to actually use sysctl(), the RAM stats reported back by the system are still bogus, i.e. you'll see the same nonsense 2GB. At least, that's what I was seeing on my MBP.

@Sean
I'll put merging your changes in for B4 on my list, so they'll be in anything forthcoming for TGEA, too.
#3
06/29/2009 (10:23 pm)
I think the problem is the it returns a 64 bit value for memory
at least according to whati can find

define HW_PHYSMEM 5 /* int: total memory */

#define HW_MEMSIZE 24 /* uint64_t: physical ram size */

/*
* XXX This information should be moved to the man page.
*
* These are the support HW selectors for sysctlbyname. Parameters that
* are byte counts or frequencies are 64 bit numbers.
* All other parameters are 32 bit numbers.
*
* hw.memsize - The number of bytes of physical memory in the system.

I think this should get the correct memory size ...i have yet to test this (from apple forums)


#include <sys/types.h>
     #include <sys/sysctl.h>
     #include <stdio.h>
 
// from sysctl.h
// HW_MEMSIZE	24		uint64_t: physical ram size 
 
int main (void)
 
{
	int mib[2];
	uint64_t memsize;
	size_t len;
 
	mib[0] = CTL_HW;
	mib[1] = HW_MEMSIZE; /*uint64_t: physical ram size */
	len = sizeof(memsize);
	sysctl(mib, 2, &memsize, &len, NULL, 0);
	printf("- memsize  = %10i k\n", memsize/1024);
	printf("- memsize  = %10i MB\n", memsize/1024/1024);
	printf("- memsize  = %10i GB\n", memsize/1024/1024/1024);
		
	return 0;
}
#4
06/30/2009 (4:25 pm)
@Andrew13:

When using the sysctlbyname( ) function in a program, you can force it to return the size of the parameter by using a NULL in place of a destination pointer so you can ensure that the destination you had in mind is the correct size, etc. At the time I wrote my code, Leopard only uses 32 bit values for the virtualized memory sizes since they're limited by to 32-bit physical addresses. I would imagine that grabbing the extended address mode values would require a larger dest variable for up to 64 GB max or 36-bits. I would also speculate that once 10.6 Snow Leopard comes along, those values *should* be changed to full 64-bit values but I don't pay Apple enough for early developer release info. =)

You also need to be aware of what you're asking SYSCTL to return as I found not one but several "memory" parameters which are most likely calculated differently: system avail, user avail, physical installed, physical wired max, etc, etc. The example you cited is using "HW_MEMSIZE" but the code I posted returns both "hw.physmem" and "hw.usermem". On my system, "hw.physmem" returns 2048 MB which is true (iMac with 2GB) and the "hw.usermem" key returns about 1800 MB plus/minus depending on what else is running, etc.

In fact, instead of writing code fragments, etc you can simply open up a Terminal window and type the queries directly since SYSCTL is a command with Darwin. So just typing "sysctl hw.usermem", it responded with "hw.usermem: 1908056064". You can also get a list (LONG!) of all the available parameters by using "sysctl -X" -- I recommend using a subset to narrow the list down such as "sysctl -X hw" or "sysctl -X machdep" for instance.

Finally, I removed the division->truncation ops in favor of just a simple bit shift so given (value) in bytes, (value >> 10) gives KB, (value >> 20) gives MB, and (value >> 30) gives GB, etc. Personal preference of course!

Sean.

EDIT: Including all the words in a sentence makes more sense!