Object Serialization is the pretty much the most useful thing you will ever need when writing custom applications. Have you ever wondered why Photoshop loads 70 Meg files in the like the blink of an eye and your cheesey program that downloads girls’ pictures from HotorNot if they have more than a 9.5 runs slow as shit?
That’s because, like a shithead, you’re not serializing your data. Serializing stores the memory of your data to a file and then loads it back in straight from the disk in an automatated fashion. Here’s how.
1. First make a shitload of data.
2. Open a CFile and a CArchive.
3. Serialize the Data.
4. Close the File.
Here comes the code:
//open the file and archive
CFile theFile;
theFile.Open("C:\\savefile.txt", CFile::modeWrite | CFile::modeCreate);
CArchive archive(&theFile, CArchive::store); //this attaches the archive to the file.
//set the above to CArchive::load when you're loading all this shit back in.
for(int i=0; i < g_dudes.size(); i++)
{
//call the serialize function for every dude.
g_dudes[i]->serialize(archive);
}
//close all the files and things.
archive.Close();
theFile.Close();
Now I know what you’re thinking. “How the fuck did my dude get a serialize function?” Well the answer is that you put it there.
Class CHerpes{
int id;
CStringArray bunchabullshit;
int serialize(CArchive& archive)
{
if( archive.IsStoring() )
{
//this is how to serialize common datatypes
archive << id;
//this is how to serialize pain in the ass datatypes
bunchabullshit.Serialize(archive);
//stl has no damn serialize function
}
//when loading, just do the reverse arrows.
else
{
archive >> id;
bunchabullshit.Serialize(archive);
}
return 0; //who cares
};
}
Yea that’s all. That should make your datasets which are super huge load super fast.

0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment