CVS: winex/memory global.c,1.10,1.11

[email protected] 31 Jul 2007 19:55:35 -0000
Newsgroups gmane.comp.emulators.winex.cvs
Message-ID <[email protected]>
Subject: winex/memory global.c,1.10,1.11Update of /var/lib/cvsd/cvsroot/winex/memory
In directory agravaine:/tmp/cvs-serv1742/memory

Modified Files:
	global.c 
Log Message:

- fix GlobalMemoryStatusEx() for Macs with >= 2G memory
- improve usage of sysctlbyname calls


Index: global.c
===================================================================
RCS file: /var/lib/cvsd/cvsroot/winex/memory/global.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- global.c	31 Jul 2007 18:02:19 -0000	1.10
+++ global.c	31 Jul 2007 19:55:33 -0000	1.11
@@ -1519,8 +1519,8 @@
     FILE *f;
 #endif
 #if defined(__FreeBSD__) || defined(__APPLE__)
-    int *tmp;
-    int size_sys;
+    unsigned int tmp;
+    size_t size_sys;
 #endif
     if (time(NULL)==cache_lastchecked) {
 	memcpy(lpmemex,&cached_memstatus,sizeof(cached_memstatus));
@@ -1578,22 +1578,22 @@
         }
     } else
 #elif defined(__FreeBSD__) || defined(__APPLE__)
-    sysctlbyname("hw.physmem", NULL, &size_sys, NULL, 0);
-    tmp = malloc(size_sys * sizeof(int));
-    sysctlbyname("hw.physmem", tmp, &size_sys, NULL, 0);
-    if (tmp && *tmp)
+    size_sys = sizeof (tmp);
+    if (sysctlbyname ("hw.physmem", &tmp, &size_sys, NULL, 0) == 0)
     {
-        lpmemex->ullTotalPhys = *tmp;
-	free(tmp);
-	sysctlbyname("hw.usermem", NULL, &size_sys, NULL, 0);
-	tmp = malloc(size_sys * sizeof(int));
-	sysctlbyname("hw.usermem", tmp, &size_sys, NULL, 0);
-	if (tmp && *tmp)
+       lpmemex->ullTotalPhys = tmp;
+
+       /* FIXME - This is actually the wrong value to use; it's actually
+          not straightforward to get the needed info on Mac OS X, judging
+          by the contortions 'top' goes through on this platform. We need
+          to examine that for ideas */
+       if (sysctlbyname ("hw.usermem", &tmp, &size_sys, NULL, 0) == 0)
 	{
-	    lpmemex->ullAvailPhys = *tmp;
-            lpmemex->ullTotalPageFile = *tmp;
-	    lpmemex->ullAvailPageFile = *tmp;
-	    lpmemex->dwMemoryLoad = lpmemex->ullTotalPhys - lpmemex->ullAvailPhys;
+            FIXME ("Need to use Apple APIs to get real available memory\n");
+	    lpmemex->ullAvailPhys = tmp;
+            lpmemex->ullTotalPageFile = tmp;
+	    lpmemex->ullAvailPageFile = tmp;
+	    lpmemex->dwMemoryLoad = (lpmemex->ullTotalPhys - lpmemex->ullAvailPhys) / (lpmemex->ullTotalPhys / 100);
 	} else
 	{
 	    lpmemex->ullAvailPhys = lpmemex->ullTotalPhys;
@@ -1601,7 +1601,6 @@
 	    lpmemex->ullAvailPageFile = lpmemex->ullTotalPhys;
 	    lpmemex->dwMemoryLoad = 0;
 	}
-	free(tmp);
 
     } else
 #endif