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

Part of the code I'm working on is to analyze the foreign file format created by other software - β€œrepeat” from the game to be more accurate. In this repetition, all actions performed by players are stored with a variable number of arguments.
My software analyzes user actions, does things such as creating a schedule of their actions per minute throughout the game, etc. ... And in order to provide comprehensive information internally, each action is translated into an object with its own methods, but with tens of thousands of actions, even for the simplest games, this analysis takes time, and now I'm looking for a way to consolidate it when the repetition has already been analyzed once.

I had a few ideas, but I'm not sure which one I should apply:
1 - some kind of serialization to save the state of action objects on the disk, so that the object can be reloaded directly from it? I’m not sure if this would have a significant impact on performance, as he would still have to create all the objects


2 - creating a large pool of each type of object before the start of the game and reuse when the user switches from playback to playback, avoiding the creation time?

I'm not sure how to proceed here, so if you have any good idea on how to quickly develop this, please feel free to share. Please note that choosing a disk space to maintain the retry status after analysis is not a problem, and these are "high-performance" gaming computers, so I can accept some restrictions on how much resources I use, while this speeds up the process.

Thank you in advance for your help.

+4
source share
5 answers
  • output each object from TComponent
  • make all the properties you want to keep published
  • create one root component as the owner of others
  • use TFileStream or TMemoryStream to store and load the root
+8
source

You currently have

GameRecordOnDisk {contains many action defintions } ---> RepresentionOfActionsInMemory 

Do you have any idea when the time will come for transformation? Read from disk? Parsing data? Creating objects? Setting up links between actions (perhaps searching for lists of things?).

I think you need to get some performance tools and analyze what is happening. Performance tuning is notoriously intuitive. You quite often find a seemingly innocuous line of code surprisingly expensive.

You may then be asked to develop a more optimized representation on disk or to make your data structures more efficient or whatever. But without facts, you risk cautiously improving your code performance by 1000%, only to find that you just removed 1% of the total overhead.

+4
source

Great idea expressed by Uwe Raabe.

As another option:

if you know the number of objects that will be created in advance: create them all in one package, and then just get access.

if it is a variable number every time, but you know that it is an order of magnitude 10,000, then create objects in packages of 100 at a time. This will slightly increase your productivity, but still. I do not think that creating objects is your main bottleneck.

0
source

As soon as your program analyzes the game file, save all your analytical information to a file with the same name as the game file, but with a different suffix.

eg. You read in X40938.log, and you print out X40938.ana (assuming you want to use ana as your suffix).

Then, whenever someone uses your program to analyze a game file, check the corresponding .ana file. If it exists, download it (fast), parse the game file again (slowly) and save the .ana file so that it becomes fast the next time.

If the game files can be updated by the program, you can compare the time stamp (last modified date) of the game file with the file of your .ana file, and if the time stamp of the game file will be less than the time stamp. ana, then you have to re-analyze.

Your concern is that creating objects again will be slow. I doubt it. I am sure that the analysis of the game data is slow. You should find loading pre-analyzed data much faster.

0
source

In MFC there is such a concept of "Serialization".

You can do this in any language. Basically, you just write procedures to go around your data structure, and as they go, they write the main data in binary form to your file.

When writing an array, make sure that you write the size of the array before its elements.

When writing a pointer-based structure, first write a logical message if the pointer is not null.

Then you write to the reader who does the same, except that he reads the array, first reads the size, selects the array, and reads the elements. At the point where you are reading the pointer, first read the boolean value. If it is 0, just make the pointer null and skip it. If not, highlight the pointer and continue reading its contents.

In MFC, these two functions are actually encoded into common routines called "Serialization". When you write, you basically do depth when you write, and the same when you read.

Since all I / O are binary, it is about as fast as possible.

0
source

All Articles