Subject: Serialization, text_Xarchive Why doesn't work?

I've tried to write my first application with Boost.Serialization library. Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error": [code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE }; class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1=(*loaded.second.begin())->get_row(0)[0]; { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; // here is this exceptions thrown } ... [/code] And here is a little bit different code, which works great: [code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE }; class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1(5.5, MEASURED); { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; } ... [/code] What is the problem? The construction (*loaded.second.begin())->get_row(0)[0] returns an OTCValue . I have compiled the boost-1.33.1 from the sources (www.boost.org). The project I've made is under KDevelop 3.2.2 (initially consol "Hello World" application) Operating System: SuSe Linux 10.0 Compiler: gcc version 4.0.2 I hope, that I've gave enouph information. If not, ask what aou need, you are welcome. Best regards, and thanks to all! -- Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit! "Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

Is it possible that m_value is uninitialized? It is a known problem that many compilers can can write uninitialized floating/double values to a text stream and then cannot read them. This topic is currently being discussd on the developer's list - as it arises all the time. Take a look a test_serial.txt with a text editor. What does it look like? Robert Ramey tkachenkok@gmx.de wrote:
I've tried to write my first application with Boost.Serialization library.
Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error":
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1=(*loaded.second.begin())->get_row(0)[0]; { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; // here is this exceptions thrown } ... [/code]
And here is a little bit different code, which works great:
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1(5.5, MEASURED); { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; } ... [/code]
What is the problem? The construction (*loaded.second.begin())->get_row(0)[0] returns an OTCValue .
I have compiled the boost-1.33.1 from the sources (www.boost.org). The project I've made is under KDevelop 3.2.2 (initially consol "Hello World" application)
Operating System: SuSe Linux 10.0 Compiler: gcc version 4.0.2
I hope, that I've gave enouph information. If not, ask what aou need, you are welcome.
Best regards, and thanks to all!

It looks as follows: 22 serialization::archive 3 0 0 5.5 1 -------- Original-Nachricht -------- Datum: Thu, 3 Aug 2006 08:14:41 -0700 Von: "Robert Ramey" <ramey@rrsd.com> An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Subject: Serialization, text_Xarchive Why doesn\'t work?
Is it possible that m_value is uninitialized? It is a known problem that many compilers can can write uninitialized floating/double values to a text stream and then cannot read them. This topic is currently being discussd on the developer's list - as it arises all the time.
Take a look a test_serial.txt with a text editor. What does it look like?
Robert Ramey
tkachenkok@gmx.de wrote:
I've tried to write my first application with Boost.Serialization library.
Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error":
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1=(*loaded.second.begin())->get_row(0)[0]; { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; // here is this exceptions thrown } ... [/code]
And here is a little bit different code, which works great:
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1(5.5, MEASURED); { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; } ... [/code]
What is the problem? The construction (*loaded.second.begin())->get_row(0)[0] returns an OTCValue .
I have compiled the boost-1.33.1 from the sources (www.boost.org). The project I've made is under KDevelop 3.2.2 (initially consol "Hello World" application)
Operating System: SuSe Linux 10.0 Compiler: gcc version 4.0.2
I hope, that I've gave enouph information. If not, ask what aou need, you are welcome.
Best regards, and thanks to all!
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

That is not a greate problem. The problems start then... The reason of the problem can be follow: one of the operator [](int Index) has two versions, which have only one difference: const OTCValue& and OTCValue&. Maybe the compiler cannot choose the necessary. But now I have another problem: I have such a class, which shouldn't be saved normally (OTCData). The reason for this: this class has a member, which should be rerialized via string, more then that, it cannot be copied (OTCDataID and OTCDataHeaderID). So I've tried to do following: #include <boost/serialization/tracking.hpp> #include <boost/serialization/split_member.hpp> namespace DataManagement { class OTCData : public IOTCData { friend class boost::serialization::access; template<class Archive> void save(Archive & ar, const unsigned int version) const { const std::string own_id=m_own_id->save_to_string(); ar & own_id; const std::string header_id=m_header_id->save_to_string(); ar & header_id; ar & m_rows; ar & m_cols; } template<class Archive> void load(Archive & ar, const unsigned int version) { std::string own_id; std::string header_id; ar & own_id; m_own_id->load_from_string(own_id); ar & header_id; m_header_id->load_from_string(header_id); ar & rows; ar & m_cols; } BOOST_SERIALIZATION_SPLIT_MEMBER(); std::auto_ptr<OTCDataID> m_own_id; std::auto_ptr<OTCDataHeaderID> m_header_id; std::vector<OTCRow> m_rows; int m_cols; // shouldn't be serialized const IOTCDataHeader * m_header; }; } Then function to save instance of OTCData: namespace DataManagement{ class DataController { void save_otcdata(const OTCData&data)const; }; void DataManagement::DataController::save_otcdata(const OTCData& data) const { std::string file_name=set_file_name(data); std::ofstream ofs(file_name.c_str()); boost::archive::text_oarchive oa(ofs); oa << data; // Here I have very long compiler error messages // which are very like the messages by trying to save nonconstant object } } I have no idea any more. I save only constants and the compilation fails! Thanks to all! -------- Original-Nachricht -------- Datum: Thu, 3 Aug 2006 08:14:41 -0700 Von: "Robert Ramey" <ramey@rrsd.com> An: boost-users@lists.boost.org Betreff: Re: [Boost-users] Subject: Serialization, text_Xarchive Why doesn\'t work?
Is it possible that m_value is uninitialized? It is a known problem that many compilers can can write uninitialized floating/double values to a text stream and then cannot read them. This topic is currently being discussd on the developer's list - as it arises all the time.
Take a look a test_serial.txt with a text editor. What does it look like?
Robert Ramey
tkachenkok@gmx.de wrote:
I've tried to write my first application with Boost.Serialization library.
Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error":
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1=(*loaded.second.begin())->get_row(0)[0]; { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; // here is this exceptions thrown } ... [/code]
And here is a little bit different code, which works great:
[code] enum Origin { UNKNOWN=0, MEASURED, AVERAGE };
class OTCValue { friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & m_value; ar & m_orig; } double m_value; Origin m_orig; ... }; ... const OTCValue val1(5.5, MEASURED); { std::ofstream ofs("test_serial.txt"); boost::archive::text_oarchive oa(ofs); oa << val1; } OTCValue val; { std::ifstream ifs("test_serial.txt"); boost::archive::text_iarchive ia(ifs); ia >> val; } ... [/code]
What is the problem? The construction (*loaded.second.begin())->get_row(0)[0] returns an OTCValue .
I have compiled the boost-1.33.1 from the sources (www.boost.org). The project I've made is under KDevelop 3.2.2 (initially consol "Hello World" application)
Operating System: SuSe Linux 10.0 Compiler: gcc version 4.0.2
I hope, that I've gave enouph information. If not, ask what aou need, you are welcome.
Best regards, and thanks to all!
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit! "Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

On 03/08/06, tkachenkok@gmx.de <tkachenkok@gmx.de> wrote:
Here is the part of code, where the boost::text_iarchive throws an exception "boost::archive::archive_exception" "what(): stream error":
You aren't the only one. I also suffered from segfaults when loading archives, both binary and text. Usually triggered when saving doubles or floats (always initialised). I tried to reduce it to a testcase, but I ran out of time, so I implemented my own archive/serialiser framework that used the same serialize() functions that I had written for boost::archive. It works, and I managed to get it to work with versioning etc (but no pointer tracking and other stuff i dont need). It uses stream.write() and stream.read() to read/write in a non-portable format, but at least it works! There IS a problem in there somewhere. I personally think its got to do with the compiler using the wrong functions or something like that, but I can't be sure. Works fine on linux, gcc4, would fail on mingw (gcc 3.3.5 i think, whatever the latest version is). I use stock boost 1.33.1 that I compile myself. see ya Paul
participants (4)
-
Konstantin Tkachenko
-
Paul
-
Robert Ramey
-
tkachenkok@gmx.de