Skip to content

Instantly share code, notes, and snippets.

@betatim
Created July 17, 2013 07:44
Show Gist options
  • Save betatim/6018538 to your computer and use it in GitHub Desktop.
Save betatim/6018538 to your computer and use it in GitHub Desktop.
On my mac it compiles with: $ g++ -g serial.cpp -o serial -lboost_serialization-mt running it create dead_pixels.archive $ ./serial somewhere I have the magic line to add to the requirements file to get it to link to boost_serialisation ...
#include <fstream>
#include <map>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/map.hpp>
int main() {
std::ofstream ofs("dead_pixels.archive", std::ios::binary);
// channel ID as key, value tells us for how
// many more cycles the pixel is dead
std::map<int, int> dead_pixels;
dead_pixels[123456] = 12;
dead_pixels[123457] = 2;
// save data to archive
{
boost::archive::binary_oarchive oa(ofs);
oa << dead_pixels;
}
// ... some time later
std::map<int,int> restored_dead_pixels;
{
std::ifstream ifs("dead_pixels.archive", std::ios::binary);
boost::archive::binary_iarchive ia(ifs);
ia >> restored_dead_pixels;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment