boost serialization/deserialization strange problem
-
hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:
#include #include #include #include #include #include #include using namespace std;
#define COUNT 26
class person;
vector v;
class person
{
public:
string _name;
int _age;
person (string name="Liviu", int age=40):_name(name),_age(age){};
friend class boost::serialization::access;
template void serialize(Archive & ar, const unsigned int version)
{
ar & _name;
ar & _age;
}
};
void save()
{
ofstream file("archiv.cst");
boost::archive::binary_oarchive oa(file);
for (int i=1; i<=COUNT; i++)
{
oa<>p;
v.push_back(p);
// cout << p._name<<" " <>i;
while (i!=2)
{
if (i==0) save();
if (i==1) load();
cin>>i;
}
}
Can you help me please? Is something wrong with the library?
-
hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:
#include #include #include #include #include #include #include using namespace std;
#define COUNT 26
class person;
vector v;
class person
{
public:
string _name;
int _age;
person (string name="Liviu", int age=40):_name(name),_age(age){};
friend class boost::serialization::access;
template void serialize(Archive & ar, const unsigned int version)
{
ar & _name;
ar & _age;
}
};
void save()
{
ofstream file("archiv.cst");
boost::archive::binary_oarchive oa(file);
for (int i=1; i<=COUNT; i++)
{
oa<>p;
v.push_back(p);
// cout << p._name<<" " <>i;
while (i!=2)
{
if (i==0) save();
if (i==1) load();
cin>>i;
}
}
Can you help me please? Is something wrong with the library?
Put your code inside a
try{}catch{}
block, and check which exception is being thrown.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
Put your code inside a
try{}catch{}
block, and check which exception is being thrown.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
the exception cannot be caught with a try - catch block i already told you what the exception is
How else can you catch it? I would suggest that you try the boost website to see what you need to do.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
How else can you catch it? I would suggest that you try the boost website to see what you need to do.
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:
#include #include #include #include #include #include #include using namespace std;
#define COUNT 26
class person;
vector v;
class person
{
public:
string _name;
int _age;
person (string name="Liviu", int age=40):_name(name),_age(age){};
friend class boost::serialization::access;
template void serialize(Archive & ar, const unsigned int version)
{
ar & _name;
ar & _age;
}
};
void save()
{
ofstream file("archiv.cst");
boost::archive::binary_oarchive oa(file);
for (int i=1; i<=COUNT; i++)
{
oa<>p;
v.push_back(p);
// cout << p._name<<" " <>i;
while (i!=2)
{
if (i==0) save();
if (i==1) load();
cin>>i;
}
}
Can you help me please? Is something wrong with the library?
dliviu wrote:
for (int i=1; i<=COUNT; i++) { person p; ia>>p; v.push_back(p); // cout << p._name<<" " <<p._age<<endl; }
When you do this... you're loading a stack variable into a dynamic heap object. The stack variable falls out of scope at the end of the execution of each for loop iteration. This isn't necessarily the problem causing the crash you're seeing, but it's definitely a problem. Correction:
vector::push_back()
does make a copy and not just keep the pointer. -
dliviu wrote:
for (int i=1; i<=COUNT; i++) { person p; ia>>p; v.push_back(p); // cout << p._name<<" " <<p._age<<endl; }
When you do this... you're loading a stack variable into a dynamic heap object. The stack variable falls out of scope at the end of the execution of each for loop iteration. This isn't necessarily the problem causing the crash you're seeing, but it's definitely a problem. Correction:
vector::push_back()
does make a copy and not just keep the pointer. -
I don't see any problem here. p is an object which when it is inserted in v it is copied. Anyway, this is not the problem. Boost library site sucks, and i have no solution to my strange problem. :(
I had to look at the implementation of vector.. you're correct, it is copied. As far as the boost site sucking, well, that's something you have to live with when using third party libraries. You can always make your own serialization class and you won't have support issues (although it'll take you some time to do it).