Jump to content
Visual Boy Advance-M
spacy51

reading/writing save states

Recommended Posts

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.

 

int utilReadInt(gzFile gzFile)
{
 int i = 0;
 utilGzRead(gzFile, &i, sizeof(int));
 return i;
}

Share this post


Link to post
Share on other sites

This indeed is a problem if you want to exchange save states between 32 bits and 64 bits machines.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×