Jump to content
  • Advertisement
Sign in to follow this  
Medice

binary and classes?

This topic is 4491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to save and load class's settings into/from a binary file? Using the same method as for structs seems to fail miserably and the program comes crashing down from the skies. // edit: c++, i'm talking about

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Paul Richardson
Remember the first u32 of a class is generally the vtable pointer, to you need to take that into account...


Only when it's a derived class, right?

Share this post


Link to post
Share on other sites
Quote:
Original post by Endar
Quote:
Original post by Paul Richardson
Remember the first u32 of a class is generally the vtable pointer, to you need to take that into account...


Only when it's a derived class, right?


Not particularly. Only when it has any virtual functions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Paul Richardson
Remember the first u32 of a class is generally the vtable pointer, to you need to take that into account...


Is the 'memory layout' of a class defined? Could you serialize a class based on that, like with structs?

Share this post


Link to post
Share on other sites
No, don't rely the location (or number of) vtable pointers; it is implementation-defined and so could be different from compiler to compiler.

You generally don't want to simply "serialize" a class or struct by doing something like write(&foo,sizeof(foo)) where foo is an instance of some class. There are a number of problems with this.

-: The vtable(s) are in there somewhere (in C++, they could exist regardless of whether or not you have a struct or class).
-: There is likely padding between data members that senselessly increase the size of the file on disk and also make it more cumbersome to read back.
-: There could be pointers in the class, which don't serialize properly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!