serialized and deserialized methods

B

bintom

I recently had a doubt about the following lines of code. I have
posted and received a satisfactory reply to it. However, a couple of
responses advised me to use serialized and deserialized methods to do
the work. Where can I find some info on what serialized and
deserialized methods are and what they can do for me.

fstream file("Group.txt", ios::ate | ios::in | ios::binary);
file.seekg(0);
while(file.read((char *)this, sizeof(*this)))
{ // some code
}
 
Ö

Öö Tiib

I recently had a doubt about the following lines of code. I have
posted and received a satisfactory reply to it. However, a couple of
responses advised me to use serialized and deserialized methods to do
the work. Where can I find some info on what serialized and
deserialized methods are and what they can do for me.

fstream file("Group.txt", ios::ate | ios::in | ios::binary);
file.seekg(0);
while(file.read((char *)this, sizeof(*this)))
{  // some code

}

How to serialize and how to deserialize is FAQ. There are no one sure
answer as people may need more or less sophisticated solutions.

The way how you did it will be nuisance to maintain. People usually
avoid it even when serializing for undo/redo mechanics.
 
J

Jonathan Lee

How to serialize and how to deserialize is FAQ. There are no one sure
answer as people may need more or less sophisticated solutions.

In case the OP is unaware, the FAQ in question is kept at
http://www.parashift.com/c++-faq-lite/

There's a whole section on serialization. For the code the OP posted,
probably only the first six or so are relevant, but you might want to
read them all to understand why it isn't such a simple problem. As a
quick example, if you were to write out a std::string via

file.write((char*)this, size(*this))

you would write the pointer std::string allocated for the string's
contents, but not the contents themselves.

--Jonathan
 
B

Brian

I recently had a doubt about the following lines of code. I have
posted and received a satisfactory reply to it. However, a couple of
responses advised me to use serialized and deserialized methods to do
the work. Where can I find some info on what serialized and
deserialized methods are and what they can do for me.

fstream file("Group.txt", ios::ate | ios::in | ios::binary);
file.seekg(0);
while(file.read((char *)this, sizeof(*this)))
{  // some code

}

I have some information about serialization on my website. I've
taken the unusual course of providing on line serialization support.


Brian Wood
http://webEbenezer.net
(651) 251-9384
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top