Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6850: serialization/deserialization does not work for more than 25 objects (very strange!!!)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-07-15 20:29:00
#6850: serialization/deserialization does not work for more than 25 objects (very
strange!!!)
--------------------------------------------------+-------------------------
Reporter: Liviu <liviu_c_dorobantu@â¦> | Owner: ramey
Type: Bugs | Status: closed
Milestone: To Be Determined | Component: serialization
Version: Boost 1.47.0 | Severity: Problem
Resolution: invalid | Keywords: serialization deserialization 25
--------------------------------------------------+-------------------------
Changes (by ramey):
* status: new => closed
* resolution: => invalid
Comment:
the default std::vector size is some number. You're not overriding that
when oyu rebuild. You might want to look into how std:vector is
serialized. I believe you should let the standard code in the library do
this for you. That is, you should change your code to:
{{{
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp> // note:use standard vector
serialization !
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
#define COUNT 26
class person;
vector<person> v;
class person
{
public:
string _name;
int _age;
person (string name="Liviu", int age=25):_name(name),_age(age){};
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & _name;
ar & _age;
}
};
void save()
{
ofstream file("archiv.cst");
boost::archive::binary_oarchive oa(file);
oa << v;
file.close();
};
void load()
{
ifstream file("archiv.cst");
boost::archive::binary_iarchive ia(file);
ia >> v;
file.close();
};
int main()
{
int i;
for (i=1; i<=COUNT; i++){
v.push_back(person("John", i));
}
cin>>i;
while (i!=2)
{
if (i==0) save();
if (i==1) load();
cin>>i;
}
}
}}}
and see how that works. I think I'm correct, so I'm going to close this
item for now.
Robert Ramey
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/6850#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:10 UTC