Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to save the state of an object for a faster reload later?

A piece of code I'm working on has to analyze a foreign file format produced by another software - a "replay" from a game to be more exact. In this replay, every actions produced by the players are saved with a variable number of arguments.
My software produces an analysis of user's action, doing stuff like producing a graph of their actions per minute throughout the game, ect ... And to give detailled informations internally every action is tranformed into an object with it's own methods, but with tens of thousand of actions even for the simplest games, this analysis takes time, and I'm now looking for a way to fasten it when the replay has already been analyzed once.

I had a couple of ideas, but I'm not sure which one I should apply:
1 - some kind of serialization to save the actions' objects state on disk, so that the object can be reloaded straight from it ? I'm not sure this would have a significant impact on performance since it would still have to do all the objects creation
2 - creating a large pool of every object type before hand and reusing them when the user move from replay to replay, avoiding the creating time ?

I'm not sure how to proceed here so if you have any good idea on how to design this in a fast way, please feel free to share. Note that taking disk space to save a replay status once analyzed is not an issue, and these are "high end" gamers' computers so i can take some liberties as to how much ressources I consume as long as it speeds up the process.

Thanks in advance for any help

like image 750
Lepidosteus Avatar asked Dec 18 '22 06:12

Lepidosteus


1 Answers

  • derive each object from TComponent
  • make all properties you want to save published
  • create one root component as the owner of the others
  • use a TFileStream or TMemoryStream to store and load the root
like image 126
Uwe Raabe Avatar answered Jan 26 '23 01:01

Uwe Raabe