
even simpler
ar & (map
Anytime you're serialization a "const" value its a red flag that you might really want to do that. "const" values are initialized when the object is created and should never subsequently change.
anyway, try:
save .. ar << data.count();. for (iter = data_.begin(); iter != data_.end(); iter++) { std::string key(iter->first); ar << key; ar << iter->second; }
load ... _data.clear() ar >> count; while(0 < count){ std::string key; int i; ar >> key; ar >> i; data_.insert( key.cstr(), // of course this won't work - but you get the idea i ); }
Robert Ramey
Denis Gabaidulin wrote:
I have following class with stl container:
class storage : { private: map
data_; friend class boost::serialization::access;
template<class Archive> void save(Archive & ar, const unsigned int version) const { map
local; constDataIter iter; for (iter = data_.begin(); iter != data_.end(); iter++) { local[iter->first] = iter->second; }
ar & local; } }
This code works, but it slowly(full copy) and consume too much memory (x2) :-(
What is the best serialization strategy with such stl containers or pointer to pod type?
I cannot change const char* to string, dont ask me why :-))
Thanks you for any advice.