Besides a probable typo (m_iNumMixtures instead of NumMixtures) the reaon why this will not work is that you need to make sure you have sufficicent memory allocated at *pMixtureWeight. For that you probably need to split serialization into save and load, and load will have to free the previously allocated memory and allocate memory of the appropriate size. Matthias On 1 Feb 2008, at 11:31, Chengyuan Ma wrote:
I have a class needs to be serialized into an XML file. I can save the object into an XML file, but i can not load it back. I found the problem is the dynamic array, "double *pMixtureWeight".
What's the correct way to serialize a dynamic array into a XML file if i don't want to change it to a vector<double>?
thx a lot!
class Model { public: Model(); virtual ~Model() ;
private: // serialization support friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int /* file_version */) { ar & boost::serialization::make_nvp("FeatureDim", FeatureDim) ; ar & boost::serialization::make_nvp("MixtureNum", NumMixtures) ;
for(int ii = 0 ; ii < m_iNumMixtures; ii ++ ) { string tag = "weight_" + boost::lexical_cast<string>(ii + 1) ; ar & boost::serialization::make_nvp(tag.c_str(), pMixtureWeight[ii]) ; } }
private: int FeatureDim; int NumMixtures; double *pMixtureWeight; };
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users