Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Handling checksums


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Wooh   Members   -  Reputation: 653

Like
0Likes
Like

Posted 29 July 2011 - 03:36 AM

I want to have a checksum in a savefile so that I can check if the savefile is not corrupted. I'm a bit unsure how to handle this the best way. At the moment I have a wrapper so that all data that is written is written to file using std::ofstream and also passed through the checksum calculation so I can later write the checksum at the end of the file.

When reading the data back I could use a similar approach letting all read data pass through the checksum calculation and when that is done I can compare the checksum. The problem with this approach is that the read routines are used while restoring the gamestate and at the end when it's time to validate the checksum I have already constructed the whole gamestate. To me this feels wrong. I feel I should validate the checksum first but then I will have to read through the file twice, once for calculating the checksum, and once when restoring the gamestate.

So, what is the best way of handling checksums, especially while reading?

Sponsor:

#2 Adam_42   Crossbones+   -  Reputation: 2619

Like
0Likes
Like

Posted 29 July 2011 - 04:40 AM

You only really have two options:

1. Read the file twice. The first time to verify the checksum, the second time to load it. This has a small possibility of going wrong if the first read works correctly, and the second one doesn't.

2. Read the whole file into temporary memory, verify the checksum, and then load from that memory into your game state. std::stringstream should make this fairly simple.

In most cases there's not much performance difference between the two since the operating system disc cache should make #1 almost as quick as #2.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS