0

I am coding a game using LibGdx. I created a level editor where you can place objects for the level. All the objects are put into a list and then the whole list is serialized by writing out the list to an object output stream. I then read in the list of objects in my game and copy the list over to my list of objects in the current level being played. On the actual user's device who is playing the game, there will be 20+ serialized level files. They will only be deserialized at this point. Is this an efficient way to do this in regards to memory and performance? Could those files take up a good chunk of memory? I noticed people use xml or Json for what I am doing. Should I be worried about having any issues the way I have done my level loading? Thanks. Let me know if my question isn't clear.

2
  • Why would files take up any memory at all? They're files. Commented Dec 23, 2014 at 1:31
  • Don't worry about performance issues until you actually find that a particular thing is a problem. Using a textual format makes debugging both ends of the software dramatically easier, and reading or writing JSON and XML usually isn't a major source of overhead. Commented Dec 23, 2014 at 8:03

2 Answers 2

1

When we were looking for slowdowns in our code we profiled it running and found a huge amount of time being spent on one thing. When we looked it turned out to be a section where an object was being duplicated by serializing it to a string and back. For some reason, the default java implementation of serialization is SLOW.

The other problem with serialization is that it's black box--if your file gets corrupted or you mess up your object enough during an upgrade you can lose everything.

Did you consider ORM and some kind of easy database? There are databases that are compiled into your code (invisible to your user) and it's pretty much just db.save(anyObject)... very easy to use.

Sign up to request clarification or add additional context in comments.

Comments

0

for a similiar question I did a short research (because I couldn't believe object serialization is slow) and i would recommend you to use JSON, as it's faster. Memory usage in terms of RAM will be the same (as soon as your object is deserialized). On disk you might want to zip it.

according to those benchmarks, jackson is faster than java serialization: benchmark deeplink

another advantage is the human readability of your json files.

2 Comments

The benchmark you cite doesn't provide any methodology or code, so it is impossible to judge its worth.
oh it does, i just linked too deeply sry. github.com/RichardHightower/json-parsers-benchmark

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.