Skip to main content
gamedev.net
🔒 Locked

Object Serialization

Started by gimp Jun 3, 2002 at 1:21 AM 1 replies 250+ views
Original Post
gimp
gimp
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
Chris Brodie
xiuhcoatl
xiuhcoatl
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
"C and C++ programmers seem to think that the shortest distance between two points is the great circle route on a spherical distortion of Euclidean space."Stephen Dewhurst
sjelkjd
sjelkjd
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.