
Here is your proposal
static map
string_map; template <class Archive> void read_string(Archive ar, string& a_string) { string s; ar >> s; // read from disk map
::iterator i = string_map.find(s); if (i == string_map.end()) { i = string_map.insert(make_pair(s, true)); }
a_string = i->first; }
void destroy_map() { string_map.clear(); }
First I would use a set rather than map as I think it would be sufficient. Second I would make this a "helper class" . Your special "Lear Archive" would be derived from an existing archive and the helper class using multiple inheritance. Look at the implemenation of shared_ptr checked into the HEADof CVS to see how to do this. class LearHelper { std::setstd::string m_strings; }; class LearArchive : binary_oarchive_impl, LearHelper { }; class lear_string : std::string { typedef mpl:_true? boost::serialization:is_wrapper; template<class Archive> void save(Archive &ar, const unsigned int version) const { std::string::iterator it = m_strings.find(*this); // if the string isn't in the set if(it != std::string::end()) m_strings.insert(*this); // serialize the one in the set ar << *it; } void load(Archive &ar, const unsigned int version) { // load the string to a temporary location std::string tstr; ar >> tsr; // look it up in the set; std::string::iterator it = m_strings.find(*this); // if the string isn't in the set if(it != std::string::end()) it = m_strings.insert(tsr); // and copy from the one in the set *this = tsr; reset_object_address(... // in case someone loads a pointer to a string } } finally, whenever you serialize a string, you use the lear_string wrapper some class ... std::sting my_string; .... save(... ar << lear_string(my_string); ... load(... ar >> lear_string(my_string); }; Food for thought. This should keep you busy for a while. Good Luck. Robert Ramey