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
78 statex.dwLength = sizeof (statex);78 statex.dwLength = sizeof (statex);
79 GlobalMemoryStatusEx(&statex);79 GlobalMemoryStatusEx(&statex);
80 return statex.ullTotalPhys / 1024 / 1024;80 return statex.ullTotalPhys / 1024 / 1024;
81#else81#elif defined Q_OS_MAC
82 return -1;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);
83#endif94#endif
84}95}
85 96