Boost logo

Boost Users :

From: Matthias Troyer (troyer_at_[hidden])
Date: 2008-02-03 18:30:49


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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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