Thursday, 26 May 2011

Developer Journal 87 - On Boost Serialization

I'm so tempted to abandon Boost Serialization.

Could the crash be due to the parent class serialization function being empty?

Being able to serialize classes with inheritance is vital. If I can’t get it to work …

Perhaps there is something wrong with the parent class Obj?

Serializing a vector of smart pointers to class Neuron.

12 neurons, crash
11 neurons, crash
2 neurons, no crash

I can make class Neuron not inherit from class Obj so I can leave that for now. I can't make class Robot and class Food not inherit from class Obj.

Serializing class Obj and a vector of smart pointers to class Obj.

12 obj, crash
2 obj, no crash
4 obj, no crash
8 obj, crash
6 obj, no crash
7 obj, crash

I'm out of ideas on trying to get Boost Serialization 1.44 to work. I've been working on it since about Developer Journal 75 21/4/11. Damn, damn, damn.

I created a basic example separate from my code and serialized a vector of 100 smart pointers to my own class. Worked. It was in XML mode and not binary mode.

I went back to my code and use XML mode. Worked fine.

I went to the basic example and switched it to binary mode. Crash.

Okay, so there's something wrong with Boost 1.44 Serialization in binary mode.

That's not too helpful. A save file with 1 robot in XML mode is about 50 megabytes. I switched to binary mode because then the save file is 0.5 megabytes. When I have about 100 robots, that's 5000 megabytes or about 0.5 gigabytes per save file.

Perhaps I can go text mode?

I'm going to try to catch the exception and see what it is first.

I'm getting an input stream error.

Tried manually closing the save file after saving. Same result.

I'm still thinking of moving away from Boost Serialization but I'll do it gradually. I'm determined to get Boost Serialization working at least poorly because I know what the problems are.

The text archive works nicely in my basic example.

Trying text archive with the simulation ...

8:47 PM


As I transition away from Boost Serialization, I'll start manually taking care of pointers.

Time to re-enable everything and check how large a save file with one robot is going to be.

I double checked the Boost 1.44 Serialization documentation again and found the following on Binary Archives.

With the binary archives I may have to set the binary flag when I open the stream ...

Yikes, for some reason I'm up to 127 seconds linking time instead of the normal 70 seconds.

The text file is only 618 KB.

Trying binary archive with output and input streams opened with binary mode.

Didn't work with my code. Trying it with my basic example. Worked.

Went back to my code and changed the following.

ofstream ofs( localFilename.c_str() );


ofstream ofs( localFilename.c_str(), ios_base::out | ios_base::binary );


ifstream ifs( filename.c_str() );


ifstream ifs( filename.c_str(), ios_base::in | ios_base::binary );

9:25 PM

It worked!

Now, if only I could do away with the ridiculously long compile and load times when I use Boost 1.44 Serialization. I've got a macro to not use Boost Serialization when I do my normal work but when I work on the serialization stuff, it takes way too long.


No comments:

Post a Comment