uint32_t Bgetsysmemsize(void) { #ifdef _WIN32 uint32_t siz = UINT32_MAX; HMODULE lib = LoadLibrary("KERNEL32.DLL"); if (lib) { aGlobalMemoryStatusExType aGlobalMemoryStatusEx = (aGlobalMemoryStatusExType)GetProcAddress(lib, "GlobalMemoryStatusEx"); if (aGlobalMemoryStatusEx) { //WinNT MEMORYSTATUSEX memst; memst.dwLength = sizeof(MEMORYSTATUSEX); if (aGlobalMemoryStatusEx(&memst)) siz = (uint32_t)min(UINT32_MAX, memst.ullTotalPhys); } else { // Yeah, there's enough Win9x hatred here that a perfectly good workaround // has been replaced by an error message. Oh well, we don't support 9x anyway. initprintf("Bgetsysmemsize(): error determining system memory size!\n"); } FreeLibrary(lib); } return siz; #elif defined _3DS return 16*1024*1024; #elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES) && !defined(GEKKO) uint32_t siz = UINT32_MAX; int64_t scpagesiz, scphyspages; #ifdef _SC_PAGE_SIZE scpagesiz = sysconf(_SC_PAGE_SIZE); #else scpagesiz = sysconf(_SC_PAGESIZE); #endif scphyspages = sysconf(_SC_PHYS_PAGES); if (scpagesiz >= 0 && scphyspages >= 0) siz = (uint32_t)min(UINT32_MAX, (int64_t)scpagesiz * (int64_t)scphyspages); //initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n", // scphyspages, scpagesiz, siz); return siz; #else return UINT32_MAX; #endif }
// // getsysmemsize() -- gets the amount of system memory in the machine // unsigned int Bgetsysmemsize(void) { #ifdef _WIN32 unsigned int siz = 0x7fffffff; HMODULE lib; WINBASEAPI BOOL WINAPI (*aGlobalMemoryStatusEx)(LPMEMORYSTATUSEX) = 0; lib = LoadLibrary("KERNEL32.DLL"); if (lib) aGlobalMemoryStatusEx = (void *)GetProcAddress(lib, "GlobalMemoryStatusEx"); if (aGlobalMemoryStatusEx) { //WinNT MEMORYSTATUSEX memst; memst.dwLength = sizeof(MEMORYSTATUSEX); if (aGlobalMemoryStatusEx(&memst)) { siz = (unsigned int)min(longlong(0x7fffffff), memst.ullTotalPhys); } } else { //Win9x MEMORYSTATUS memst; GlobalMemoryStatus(&memst); siz = (unsigned int)memst.dwTotalPhys; } if (lib) FreeLibrary(lib); return siz; #elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES) unsigned int siz = 0x7fffffff; long scpagesiz, scphyspages; #ifdef _SC_PAGE_SIZE scpagesiz = sysconf(_SC_PAGE_SIZE); #else scpagesiz = sysconf(_SC_PAGESIZE); #endif scphyspages = sysconf(_SC_PHYS_PAGES); if (scpagesiz >= 0 && scphyspages >= 0) siz = (unsigned int)min(longlong(0x7fffffff), (int64)scpagesiz * (int64)scphyspages); //initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n", // scphyspages, scpagesiz, siz); return siz; #else return 0x7fffffff; #endif }