History

Can get total memory on Mac

NissimHadar committed 7 years ago

Commit a3dde611 parent 9c00bdc1 file · +13 −2Browse files

Showing the changes to interface/src/scripting/PlatformInfoScriptingInterface.cpp (1 of 1 file). Show all

Unified · Split

interface/src/scripting/PlatformInfoScriptingInterface.cpp+13−2
@@ -78,8 +78,19 @@ int PlatformInfoScriptingInterface::getTotalSystemMemoryMB() { · 77 unmodified lines
7878 statex.dwLength = sizeof (statex);
7979 GlobalMemoryStatusEx(&statex);
8080 return statex.ullTotalPhys / 1024 / 1024;
81−#else
82− return -1;
81+#elif defined Q_OS_MAC
82+ FILE* stream = popen("sysctl -a | grep hw.memsize", "r");
83+
84+ std::ostringstream hostStream;
85+ while (!feof(stream) && !ferror(stream)) {
86+ char buf[128];
87+ int bytesRead = fread(buf, 1, 128, stream);
88+ hostStream.write(buf, bytesRead);
89+ }
90+
91+ QString result = QString::fromStdString(hostStream.str());
92+ QStringList parts = result.split(' ');
93+ return (int)(parts[1].toDouble() / 1024 / 1024);
8394 #endif
8495 }
8596