Hi,
what are the options to reduce executable footprint when using boost serialization library?
I just tried the boost serialization library because I'd like to store and load polymorphic classes on a stream, binary as well as xml. The library seems to meet these needs very well, however, I am working on an embedded platform with limited memory resources (executable size < 2MBs), and my small test case somewhat scares me: The resulting executable generated by GCC on Cygwin is (no optimizations) 1.5MB! Here is the source (based on an example from boost pointer container library):
// headers, usings etc...
BOOST_IS_ABSTRACT(animal)
BOOST_CLASS_EXPORT(mammal)
BOOST_CLASS_EXPORT(bird)
int main()
{
vector<animal *> the_zoo1, the_zoo2;
// b.t.w., would boost::ptr_vector<animal> or vector<boost::shared_ptr<animal> > be better?
the_zoo1.push_back(new bird("dodo", 10.0));
// bird has a string and a float member, both are to be serialized
// create and open a character archive for output
ofstream ofs("test.bin", std::ios::binary);
boost::archive::binary_oarchive oa(ofs);
oa & the_zoo1;
ofs.close();
std::ifstream ifs("test.bin", std::ios::binary);
boost::archive::binary_iarchive ia(ifs);
ia & the_zoo2;
ifs.close();
the_zoo2.back()->eat();
// create and open an xml archive for output
ofs.open("test.xml");
boost::archive::xml_oarchive oa2(ofs);
oa2 & BOOST_SERIALIZATION_NVP(the_zoo1);
ofs.close();
ifs.open("test.xml");
boost::archive::xml_iarchive ia2(ifs);
ia2 & BOOST_SERIALIZATION_NVP(the_zoo2);
ifs.close();
the_zoo2.back()->eat();
// cleanup etc...
return 0;
}
Time-performance is not critical in my application, so virtual member calls for example would be preferred before template instances... any tips are welcome! I might test the Eternity library too to see how it behaves concerning footprint, however, the Eternity archives seem not to support general iostreams, but assumes you want to work with files exlusively, unless you want to derive your own archives.
Thanks,
Mats