| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <fstream>
|
|---|
| 4 | #include <string.h>
|
|---|
| 5 |
|
|---|
| 6 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 7 | #include <boost/serialization/binary_object.hpp>
|
|---|
| 8 |
|
|---|
| 9 | int main()
|
|---|
| 10 | {
|
|---|
| 11 | for (unsigned i=0; i<256; ++i) {
|
|---|
| 12 | char f[100];
|
|---|
| 13 | sprintf(f, "test-%d.xml", i);
|
|---|
| 14 | fprintf(stderr, "Writing to %s\n", f);
|
|---|
| 15 | std::ofstream ofs(f);
|
|---|
| 16 |
|
|---|
| 17 | boost::archive::text_oarchive archive(ofs);
|
|---|
| 18 | unsigned int serializedStateSize=16;
|
|---|
| 19 |
|
|---|
| 20 | //Create a chunk of memory which is larger than the size that will
|
|---|
| 21 | //be written to disk
|
|---|
| 22 | unsigned extraSpace=16;
|
|---|
| 23 | char* serializedState = new char[serializedStateSize+extraSpace];
|
|---|
| 24 |
|
|---|
| 25 | //Initialize all of the memory to i (changing on each iteration)
|
|---|
| 26 | memset(serializedState, i, serializedStateSize+extraSpace);
|
|---|
| 27 | //Initialize only the memory that should be written to 0
|
|---|
| 28 | memset(serializedState, 0, serializedStateSize);
|
|---|
| 29 |
|
|---|
| 30 | //Write the memory to file, specify only the size that has been set to 0
|
|---|
| 31 | archive << boost::serialization::make_binary_object(serializedState,
|
|---|
| 32 | serializedStateSize);
|
|---|
| 33 | ofs.close();
|
|---|
| 34 | delete[] serializedState;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | return 0;
|
|---|
| 38 | }
|
|---|