diff options
author | txtsd <code@ihavea.quest> | 2022-11-04 11:58:58 +0530 |
---|---|---|
committer | txtsd <code@ihavea.quest> | 2022-01-23 02:12:03 +0530 |
commit | 6961a39cd20a63116bb562d61472c31f28ea8738 (patch) | |
tree | 6d3f700354c02087e607cfc22ea4b5f1e5cbd308 | |
parent | 2cf4d5f8ecd4afb1179b5a4e3bf694bcd359b628 (diff) | |
download | PrismLauncher-6961a39cd20a63116bb562d61472c31f28ea8738.tar.gz PrismLauncher-6961a39cd20a63116bb562d61472c31f28ea8738.tar.bz2 PrismLauncher-6961a39cd20a63116bb562d61472c31f28ea8738.zip |
feat: Assign java max mem based on system RAM
If the system has <6GB RAM, it uses (system RAM / 1.5)
If the system has >=6GB, it uses 4GB
Signed-off-by: txtsd <code@ihavea.quest>
-rw-r--r-- | launcher/Application.cpp | 16 | ||||
-rw-r--r-- | launcher/Application.h | 2 |
2 files changed, 17 insertions, 1 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 5772d7ca..c3c76854 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -566,7 +566,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) // Memory m_settings->registerSetting({"MinMemAlloc", "MinMemoryAlloc"}, 512); - m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, 4096); + m_settings->registerSetting({"MaxMemAlloc", "MaxMemoryAlloc"}, suitableMaxMem()); m_settings->registerSetting("PermGen", 128); // Java Settings @@ -1633,3 +1633,17 @@ QString Application::getUserAgentUncached() return BuildConfig.USER_AGENT_UNCACHED; } + +int Application::suitableMaxMem() +{ + float totalRAM = (float)Sys::getSystemRam() / (float)Sys::mebibyte; + int maxMemoryAlloc; + + // If totalRAM < 6GB, use (totalRAM / 1.5), else 4GB + if (totalRAM < (4096 * 1.5)) + maxMemoryAlloc = (int) (totalRAM / 1.5); + else + maxMemoryAlloc = 4096; + + return maxMemoryAlloc; +} diff --git a/launcher/Application.h b/launcher/Application.h index 8fa0ab10..280c842f 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -198,6 +198,8 @@ public: void ShowGlobalSettings(class QWidget * parent, QString open_page = QString()); + int suitableMaxMem(); + signals: void updateAllowedChanged(bool status); void globalSettingsAboutToOpen(); |