implemented RAM detection function

backup
LinuxMint4Ever 2019-10-17 02:16:30 +02:00
parent c1b67d89d7
commit 5b29e703db
1 changed files with 17 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import os
import os, psutil
# java -Xmx$RAM$ -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=$NATIVES$ -cp $LIBRARIES$ net.minecraft.launchwrapper.Launch --username $USERNAME$ --version 1.7.10-Forge10.13.4.1614-1.7.10 --gameDir $GAMEDIR$ --assetsDir $ASSETS$ --assetIndex 1.7.10 --uuid $UUID$ --accessToken $ACCESSTOKEN$ --userProperties {} --userType mojang --width $WINDOWWIDTH$ --height $WINDOWHEIGHT$ --tweakClass cpw.mods.fml.common.launcher.FMLTweaker
# $RAM$ the amount of RAM with postfix (k, M, G ...)
@ -13,7 +13,7 @@ import os
game_properties = {
"window width": "1366",
"window height": "768",
"ram": autoram(),
"ram": "4G",
"username": None,
"uuid": None,
"access token": None,
@ -27,9 +27,21 @@ command = None
full_command = None
def autoram():
return "4G"
# TODO: detect available RAM
def autoram(minram, maxram, balance):
ram_available = psutil.virtual_memory().available
# not enough memory
if ram_available < minram:
# TODO: raise an exception
return -1
# plenty of memory
elif ram_available > maxram+balance:
return maxram
# enough memory but we do not want to occupy all
elif float(ram_available)*float(maxram)/float(maxram+balance) > minram:
return int(float(ram_available)*float(maxram)/float(maxram+balance))
# barely enough memory
elif ram_available > minram or ram_available == minram:
return ram_available
def launch():
global command