#include #include #include #include #include #include int main() { for (unsigned i=0; i<256; ++i) { char f[100]; sprintf(f, "test-%d.xml", i); fprintf(stderr, "Writing to %s\n", f); std::ofstream ofs(f); boost::archive::text_oarchive archive(ofs); unsigned int serializedStateSize=16; //Create a chunk of memory which is larger than the size that will //be written to disk unsigned extraSpace=16; char* serializedState = new char[serializedStateSize+extraSpace]; //Initialize all of the memory to i (changing on each iteration) memset(serializedState, i, serializedStateSize+extraSpace); //Initialize only the memory that should be written to 0 memset(serializedState, 0, serializedStateSize); //Write the memory to file, specify only the size that has been set to 0 archive << boost::serialization::make_binary_object(serializedState, serializedStateSize); ofs.close(); delete[] serializedState; } return 0; }