Archived

This topic is now archived and is closed to further replies.

Object Serialization

This topic is 5676 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

inline void CMemento::Set(const unsigned int a_Data) { m_Data.resize(m_Data.size() + sizeof(unsigned int)); unsigned char* p = &m_Data.back() - sizeof(unsigned int); p = a_Data; } (This doesn''t work BTW, I''ve never been string with pointer syntax) I''m attempting to write a class that can store a classes data in a standard unsigned char* array. This data will be then used for saves and networking. If you know a better way of pushing arbitrarily sized data in to a std::vector I''d live to hear about it... Chris Brodie http:\\fourth.flipcode.com

Share this post


Link to post
Share on other sites
I posted this a few weeks back and didn''t get a lot of feedback on it. I may be out to lunch - sorry if thats the case.. The basic code works and could be used for what you are talking about. What you would want to do is build the "serializing" class the way Fruny suggested (and I eluded to). Then, instead of worrying about how to save an arbitrary sized char* array - just let each class worry about how to save and restore it''s data to a stream. Then you can either send the stream to the network, disk, etc..

What I proposed was just encapsulating all the data into a DATA struct so that it was faster and easier to move the data block. With pointers and vectors you need to walk the data manually. I just whipped together a few helper templates to keep the main code clean.

http://www.gamedev.net/community/forums/topic.asp?topic_id=96360

Hope that helps -

#dth-0

Share this post


Link to post
Share on other sites
Hmm, why don''t you write a network protocol class that derives from basic_stream? Then you can overload operator>> and << for any class you want to serialize...and it''d work over a network, to a string, and to files.

Share this post


Link to post
Share on other sites