Question

in a tile based game, I store some data via json, and the json file contains the names of classes with their data.

Is it a problem to instantiate a new class each time I want to add a new object? (which ends up to 100 instantiations). I tried to use static classes, but because I add a new object each time, that can differ from the previous one, I need to instantiate a new class, so I think the static class is not the right option.

Is there a third option possible?

Was it helpful?

Solution

The amount of objects should be multiplied by their sizes. In general 100 objects should not be a problem. It might be a problem if you throw them away and recreate them 60 times a second.

The resulting memory footprint and the amount of garbage collection runs might then be a problem.

Do the math, do not optimize prematurely, and post the results to get more precise advice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top