Post Reply 
 
Thread Rating:
  • 43 Votes - 2.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading/writing save states
Author Message
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #1
reading/writing save states
I noticed that when reading or writing to a save state, the core uses sizeof() to determine the number of bytes to read.

This will make save states incompatible when compiled on a system where integers are not 4 bytes.

Code:
int utilReadInt(gzFile gzFile)
{
  int i = 0;
  utilGzRead(gzFile, &i, sizeof(int));
  return i;
}
(This post was last modified: 10-29-2008 10:33 PM by spacy51.)
10-29-2008 08:12 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 1,472
Joined: Mar 2008
Reputation: 13
Post: #2
RE: reading/writing save states
hasn't been a problem so far.

10-29-2008 09:48 PM
Visit this user's website Find all posts by this user Quote this message in a reply
bgK Offline
VBA-M Contributor
*****

Posts: 101
Joined: Apr 2008
Reputation: 1
Post: #3
RE: reading/writing save states
This indeed is a problem if you want to exchange save states between 32 bits and 64 bits machines.
10-29-2008 09:56 PM
Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 1,472
Joined: Mar 2008
Reputation: 13
Post: #4
RE: reading/writing save states
oh?

well as long as the fix is able to read the current format, so as to load and save them to the new.

10-30-2008 01:31 AM
Visit this user's website Find all posts by this user Quote this message in a reply
SCHUMI4EVER Offline
Super Moderator
******

Posts: 152
Joined: Mar 2008
Reputation: 2
Post: #5
RE: reading/writing save states
(10-29-2008 09:56 PM)bgK Wrote:  This indeed is a problem if you want to exchange save states between 32 bits and 64 bits machines.

Wait, so all my saves made in XP will stop working when I switch to Vista Home Premium 64bit?
10-30-2008 11:28 PM
Find all posts by this user Quote this message in a reply
bgK Offline
VBA-M Contributor
*****

Posts: 101
Joined: Apr 2008
Reputation: 1
Post: #6
RE: reading/writing save states
If you use a 64bits build of VBA-M and the bug is not fixed, yes.
10-30-2008 11:30 PM
Find all posts by this user Quote this message in a reply
SCHUMI4EVER Offline
Super Moderator
******

Posts: 152
Joined: Mar 2008
Reputation: 2
Post: #7
RE: reading/writing save states
If I continue to use a 32bit build then everything will be fine though?

There has not been a 64bit build in a while so I was planning on using the 32bit build anyways.
10-30-2008 11:40 PM
Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #8
RE: reading/writing save states
As I said, it's only a problem when int is not 4 bytes. IIRC, on Windows 64 integers are still 4 bytes, only pointers are 8 bytes long automatically.
10-31-2008 03:42 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Tantric Offline
Junior Member
**

Posts: 17
Joined: Oct 2008
Reputation: 0
Post: #9
RE: reading/writing save states
Actually you do make a good point (I think). This is something to avoid. This can be a problem for big endian vs little endian architecture. I actually don't use any of this code to avoid running into such problems =)
Here's a post I happened across just yesterday:
http://www.tehskeen.com/forums/showthread.php?p=43389

See shagkur's response.
10-31-2008 04:29 AM
Find all posts by this user Quote this message in a reply
bgK Offline
VBA-M Contributor
*****

Posts: 101
Joined: Apr 2008
Reputation: 1
Post: #10
RE: reading/writing save states
(10-31-2008 03:42 AM)spacy51 Wrote:  As I said, it's only a problem when int is not 4 bytes. IIRC, on Windows 64 integers are still 4 bytes, only pointers are 8 bytes long automatically.

My mistake, then. However I know for sure it'll be a problem on Linux and MacOS 64bits where sizeof(int) is 8.
10-31-2008 06:47 PM
Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 1,472
Joined: Mar 2008
Reputation: 13
Post: #11
RE: reading/writing save states
so the int should be dynamic, rather then static?

11-01-2008 12:35 AM
Visit this user's website Find all posts by this user Quote this message in a reply
spacy51 Offline
VBA-M Developer
*******

Posts: 451
Joined: Mar 2008
Reputation: 3
Post: #12
RE: reading/writing save states
(11-01-2008 12:35 AM)Squall Leonhart Wrote:  so the int should be dynamic, rather then static?

No, the other way round. Instead of sizeof(int), which may vary depending on the compiler/platform, we should use a static number of bytes per value, and declare the file as little-endian.
11-01-2008 07:44 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Squall Leonhart Offline
The Admin with the Gunblade
*******

Posts: 1,472
Joined: Mar 2008
Reputation: 13
Post: #13
RE: reading/writing save states
oh, that makes complete sense now.

11-04-2008 10:58 AM
Visit this user's website Find all posts by this user Quote this message in a reply
lanceaugust31 Offline
Junior Member
**

Posts: 1
Joined: Sep 2009
Reputation: 0
Post: #14
RE: reading/writing save states
When reading or writing to a save state, the core uses sizeof() to determine the number of bytes to read. what should we do if in that case? Badger


__________________
Freelance writing
09-01-2009 02:34 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: