ARTICLE AD BOX
I am self-taught, so I apologize if the title uses terms incorrectly.
I am trying to write a Minecraft mod that adds some RPG mechanics to the game. BUT more importantly, for this question, it potentially allows other users to add their own RPG systems to the mod, creating a growing list of variables.
Right now, the variables are declared in "RPG System Classes" and loaded into another "Register Class" that houses several arrays, one for each variable. I got to thinking "Where is that data going to be stored?" and I don't actually know, but I was worried it might be stored in RAM memory. So then, if you get enough variables, or RPG systems, or both, it could cause some bloat that is unneeded.
So I looked into other ways of assessing the information and found that I could load the "RPG System Classes" themselves into an array in the "Register Class" as strings. Then I can use reflection to access the variables. And I'm hoping that's a RAM friendly way of going about things.
So a sub question is: Does either method affect RAM like I think it does or am I totally in the wrong?
But my main question is: What is the best practice for saving this kind of modular information to a Java program? Is it the arrays, reflection, or some other implementation I'm unaware of?
Thank you in advance.
Edit: Thanks everyone, I think I overthought this by a lot. Like A LOT A LOT. Also I was just straight up wrong on the RAM stuff. For now I'll stick to the arrays instead.
Someone said it would be helpful if I posted some code so I shall.
An RPG System Code:
public class GenericRPGSystem { //set default values static String name = "rpgsystem.grpg.name"; static boolean enabled = true; static List<String> description = List.of("rpgsystem.grpg.desc1"); static int maxLevel = 10; static int startingLevel = 1; static int[] expList; public static void init() { expList = ArrayUtils.addAll(expList, 1000); expList = ArrayUtils.addAll(expList, 2000); expList = ArrayUtils.addAll(expList, 3000); expList = ArrayUtils.addAll(expList, 4000); expList = ArrayUtils.addAll(expList, 5000); expList = ArrayUtils.addAll(expList, 6000); expList = ArrayUtils.addAll(expList, 7000); expList = ArrayUtils.addAll(expList, 8000); expList = ArrayUtils.addAll(expList, 9000); expList = ArrayUtils.addAll(expList, 10000); //Register if (enabled) { RPGSystemRegister.register(name, description, startingLevel, maxLevel, expList); } }}
Register Class:
public class RPGSystemRegister { static String[] rpgSystems; static List<String> rpgSystemsList; static List<List<String>> descriptions = new ArrayList<>(); static int[] startingLevels; static int[] maxLevels; static List<int[]> expLists = new ArrayList<>(); public static void register(String name, List<String> description, int startingLevel, int maxLevel, int[] expList){ rpgSystems = ArrayUtils.addAll(rpgSystems, name); rpgSystemsList = Arrays.asList(rpgSystems); descriptions.add(description); startingLevels = ArrayUtils.addAll(startingLevels, startingLevel); maxLevels = ArrayUtils.addAll(maxLevels, maxLevel); expLists.add(expList); } public static String[] getRpgSystems() { return rpgSystems; } public static List<String> getRpgSystemsList() { return rpgSystemsList; } public static List<@NotNull List<String>> getDescriptions() { return descriptions; } public static int[] getStartingLevels() { return startingLevels; } public static int[] getMaxLevels() { return maxLevels; } public static List<int[]> getExpLists() { return expLists; }}
