|
Boost Users : |
From: michalurbanski (michalurbanski_at_[hidden])
Date: 2008-06-26 03:03:45
Thanks for the reply.
Is there any way to make it work if I want to allocate a block of memory which size depends on the other serialized elements?
For example, how do I deserialize an object with attribues constructed like this:
Test(int a, int b) {
this->a = a;
this->b = b;
this->c = new float[a*b];
}
Regards,
MU.
Dnia 26 czerwca 2008 8:58 Matthias Troyer <troyer_at_[hidden]> napisaÅ(a):
> The reason is that array deserialization does not allocate memory for
> the array, but assumes that the memory has already been allocated. In
> your case, you allocate memory in the constructor taking three
> arguments, but not in the default constructor. Hence the segmentation
> fault.
>
> Matthias
>
>
>
> On Jun 25, 2008, at 10:04 PM, michalurbanski wrote:
>
> > Hi all,
> >
> > I have a problem deserializing an array. With the code (1) I get a
> > Segmenetation Fault with stacktrace (2).
> >
> > Any help appriciated.
> >
> > Kind regards,
> > MU.
> >
> >
> > ------------------------------------------------------------
> > Attachment (1):
> >
> > #include
> > #include
> > #include
> > #include
> > #include
> > #include
> >
> > using namespace std;
> >
> > class Test {
> > private:
> > friend class boost::serialization::access;
> >
> > template
> > void serialize(Archive & ar, const unsigned int version) {
> > ar & BOOST_SERIALIZATION_NVP(a);
> > ar & BOOST_SERIALIZATION_NVP(b);
> > ar & boost::serialization::make_array(c, 1);
> > }
> >
> > int a;
> > int b;
> > float* c;
> > public:
> > inline Test() {
> > c = 0;
> > }
> >
> > inline Test(int a, int b, float c) {
> > this->a = a;
> > this->b = b;
> > this->c = new float[1];
> > this->c[0] = c;
> > }
> >
> > inline void display() {
> > cout cout cout }
> > };
> >
> > BOOST_CLASS_EXPORT(Test)
> >
> > int main() {
> > // SERIALIZE:
> > std::ofstream ofs("filename.xml");
> >
> > Test* t = new Test(1, 2, 3.3);
> >
> > boost::archive::xml_oarchive oa(ofs);
> > oa
> > ofs.close();
> >
> > // DESERIALIZE:
> > std::ifstream ifs("filename.xml");
> > Test* t2;
> >
> > boost::archive::xml_iarchive ia(ifs);
> > ia >> BOOST_SERIALIZATION_NVP(t2);
> >
> > t2->display();
> >
> > return 0;
> > }
> >
> > ------------------------------------------------------------
> > Attachment 2:
> >
> > 51 std::__convert_to_v() 0xb7e6bc5f
> > 50 std::num_get std::char_traits
> >>> ::do_get() 0xb7e33c8a
> > 49 std::istream::operator>>() 0xb7e1c9c7
> > 48
> > boost::archive::basic_text_iprimitive::load()
> > /usr/local/include/boost-1_35/boost/archive/
> > basic_text_iprimitive.hpp:80
> > 0x0804e687
> > 47
> > boost
> > ::archive
> > ::xml_iarchive_impl::load() /
> > usr/local/include/boost-1_35/boost/archive/xml_iarchive.hpp:58
> > 0x0804e6a9
> > 46
> > boost
> > ::archive::load_access::load_primitive float>()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:96
> > 0x0804e6c4
> > 45
> > boost
> > ::archive::detail::load_non_pointer_type float>::load_primitive::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:339
> > 0x0804e6de
> > 44
> > boost
> > ::archive::detail::load_non_pointer_type float>::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:414
> > 0x0804e6f8
> > 43 boost::archive::load()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:561
> > 0x0804e712
> > 42
> > boost
> > ::archive
> > ::detail
> > ::common_iarchive
> > ::load_override()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > common_iarchive.hpp:59
> > 0x0804e736
> > 41
> > boost
> > ::archive
> > ::basic_xml_iarchive
> > ::load_override()
> > /usr/local/include/boost-1_35/boost/archive/basic_xml_iarchive.hpp:81
> > 0x0804e77a
> > 40
> > boost
> > ::archive
> > ::xml_iarchive_impl
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/xml_iarchive.hpp:74
> > 0x0804e7b6
> > 39
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::operator>> const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:63
> > 0x0804e7e2
> > 38
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive::xml_iarchive>::operator&
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:70
> > 0x0804e812
> > 37
> > boost
> > ::serialization
> > ::array::serialize() /usr/local/
> > include/boost-1_35/boost/serialization/array.hpp:39
> > 0x0804e86b
> > 36
> > boost::serialization::access::serialize boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/serialization/access.hpp:109
> > 0x0804e89b
> > 35 boost::serialization::serialize boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/serialization/serialization.hpp:81
> > 0x0804e8bd
> > 34 boost::serialization::serialize_adl boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/serialization/serialization.hpp:
> > 140
> > 0x0804e8fb
> > 33
> > boost
> > ::archive::detail::load_non_pointer_type boost::serialization::array >::load_only::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:349
> > 0x0804e91e
> > 32
> > boost
> > ::archive::detail::load_non_pointer_type boost::serialization::array >::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:414
> > 0x0804e938
> > 31 boost::archive::load boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:561
> > 0x0804e952
> > 30 boost::archive::load_wrapper boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:583
> > 0x0804e96c
> > 29 boost::archive::load boost::serialization::array >()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:589
> > 0x0804e98e
> > 28
> > boost
> > ::archive
> > ::detail
> > ::common_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > common_iarchive.hpp:59
> > 0x0804e9b2
> > 27
> > boost
> > ::archive
> > ::basic_xml_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/basic_xml_iarchive.hpp:66
> > 0x0804e9d4
> > 26
> > boost
> > ::archive
> > ::xml_iarchive_impl
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/xml_iarchive.hpp:74
> > 0x0804e9f6
> > 25
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::operator>>
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:63
> > 0x0804ea22
> > 24
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::operator& const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:70
> > 0x0804ea52
> > 23 Test::serialize()
> > /home/wojtek/workspaceCDT/test_serial/src/main.cpp:18 0x0804eaf9
> > 22
> > boost::serialization::access::serialize Test>() /usr/local/include/boost-1_35/boost/serialization/access.hpp:
> > 109
> > 0x0804eb1b
> > 21 boost::serialization::serialize Test>()
> > /usr/local/include/boost-1_35/boost/serialization/serialization.hpp:81
> > 0x0804eb3d
> > 20 boost::serialization::serialize_adl Test>()
> > /usr/local/include/boost-1_35/boost/serialization/serialization.hpp:
> > 140
> > 0x0804eb7b
> > 19 boost::archive::detail::iserializer Test>::load_object_data()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:160
> > 0x0804ec28
> > 18 boost::archive::detail::basic_iarchive::load_object() 0xb7ee30bc
> > 17
> > boost
> > ::archive::detail::load_non_pointer_type Test>::load_standard::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:364
> > 0x0804ed2b
> > 16
> > boost
> > ::archive::detail::load_non_pointer_type Test>::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:414
> > 0x0804ed46
> > 15 boost::archive::load()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:561
> > 0x0804ed60
> > 14
> > boost
> > ::archive
> > ::detail
> > ::common_iarchive::load_override()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > common_iarchive.hpp:59
> > 0x0804ed84
> > 13
> > boost
> > ::archive
> > ::basic_xml_iarchive
> > ::load_override()
> > /usr/local/include/boost-1_35/boost/archive/basic_xml_iarchive.hpp:81
> > 0x0804edc8
> > 12
> > boost
> > ::archive
> > ::xml_iarchive_impl
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/xml_iarchive.hpp:74
> > 0x0804ee04
> > 11
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive::xml_iarchive>::operator>>
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:63
> > 0x0804ee30
> > 10
> > boost
> > ::archive::detail::pointer_iserializer Test>::load_object_ptr()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:303
> > 0x0804ef27
> > 9 boost::archive::detail::basic_iarchive_impl::load_pointer()
> > 0xb7ee3fc4
> > 8 boost::archive::detail::basic_iarchive::load_pointer() 0xb7ee3159
> > 7
> > boost
> > ::archive::detail::load_pointer_type Test*>::invoke()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:479
> > 0x0804ffa6
> > 6 boost::archive::load()
> > /usr/local/include/boost-1_35/boost/archive/detail/iserializer.hpp:561
> > 0x08050000
> > 5
> > boost
> > ::archive
> > ::detail
> > ::common_iarchive
> > ::load_override()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > common_iarchive.hpp:59
> > 0x08050024
> > 4
> > boost
> > ::archive
> > ::basic_xml_iarchive
> > ::load_override()
> > /usr/local/include/boost-1_35/boost/archive/basic_xml_iarchive.hpp:81
> > 0x08050068
> > 3
> > boost
> > ::archive
> > ::xml_iarchive_impl
> > boost
> > ::archive
> > ::xml_iarchive>::load_override
> > const>()
> > /usr/local/include/boost-1_35/boost/archive/xml_iarchive.hpp:74
> > 0x080500a4
> > 2
> > boost
> > ::archive
> > ::detail
> > ::interface_iarchive
> > boost
> > ::archive
> > ::xml_iarchive>::operator>> const>()
> > /usr/local/include/boost-1_35/boost/archive/detail/
> > interface_iarchive.hpp:63
> > 0x080500d0
> > 1 main() /home/wojtek/workspaceCDT/test_serial/src/main.cpp:61
> > 0x0804c542
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> 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