|
Boost Users : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2007-01-03 11:57:53
I've looked at your program and attempted to compile it.
Basically it seems OK but for one arcane point.
std::string is unique in that it is treated as a primitive datatype for
purposes of serialization. This is the an exception to the general rule
that only C++ primitives are treated this way. Pointer to prmitives are by
default set to "not tracked" and shared_ptr serialization requires that all
types serialized be implemented with tracking enabled. So you've stumbled
upon an unusual case.
The rationale for doing this is that most programs use primitives and
strings all over the place in a program and we don't want to be tracking all
instances of one of these types just because in one case it happens to be
used as serializable pointer.
The usual way to handle this is to create an wrapper for string which is
trackable. Something like:
class trackable_string : public std::string
{
template<class Archive>
serialize(Archive & ar, const unsigned int version){
ar & m_string;
}
private:
std::string m_string;
trackable_sting(
};
In theory, the compiler shouldn't emit any extra code when compiled for
release.
I believe this will address the issue with this program.
Robert Ramey
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net