+ Cvar_RegisterVariable (&developer_memoryreportlargerthanmb);
+ Cvar_RegisterVariable (&sys_memsize_physical);
+ Cvar_RegisterVariable (&sys_memsize_virtual);
+
+#if defined(WIN32)
+#ifdef _WIN64
+ {
+ MEMORYSTATUSEX status;
+ // first guess
+ Cvar_SetValueQuick(&sys_memsize_virtual, 8388608);
+ // then improve
+ status.dwLength = sizeof(status);
+ if(GlobalMemoryStatusEx(&status))
+ {
+ Cvar_SetValueQuick(&sys_memsize_physical, status.ullTotalPhys / 1048576.0);
+ Cvar_SetValueQuick(&sys_memsize_virtual, min(sys_memsize_virtual.value, status.ullTotalVirtual / 1048576.0));
+ }
+ }
+#else
+ {
+ MEMORYSTATUS status;
+ // first guess
+ Cvar_SetValueQuick(&sys_memsize_virtual, 2048);
+ // then improve
+ status.dwLength = sizeof(status);
+ GlobalMemoryStatus(&status);
+ Cvar_SetValueQuick(&sys_memsize_physical, status.dwTotalPhys / 1048576.0);
+ Cvar_SetValueQuick(&sys_memsize_virtual, min(sys_memsize_virtual.value, status.dwTotalVirtual / 1048576.0));
+ }
+#endif
+#else
+ {
+ // first guess
+ Cvar_SetValueQuick(&sys_memsize_virtual, (sizeof(void*) == 4) ? 2048 : 268435456);
+ // then improve
+ {
+ // Linux, and BSD with linprocfs mounted
+ FILE *f = fopen("/proc/meminfo", "r");
+ if(f)
+ {
+ static char buf[1024];
+ while(fgets(buf, sizeof(buf), f))
+ {
+ const char *p = buf;
+ if(!COM_ParseToken_Console(&p))
+ continue;
+ if(!strcmp(com_token, "MemTotal:"))
+ {
+ if(!COM_ParseToken_Console(&p))
+ continue;
+ Cvar_SetValueQuick(&sys_memsize_physical, atof(com_token) / 1024.0);
+ }
+ if(!strcmp(com_token, "SwapTotal:"))
+ {
+ if(!COM_ParseToken_Console(&p))
+ continue;
+ Cvar_SetValueQuick(&sys_memsize_virtual, min(sys_memsize_virtual.value , atof(com_token) / 1024.0 + sys_memsize_physical.value));
+ }
+ }
+ fclose(f);
+ }
+ }
+ }
+#endif