|
Boost Users : |
From: Mahesh Venkitachalam (mkvenkit.vc_at_[hidden])
Date: 2007-11-26 04:25:25
I'd like to add the following to the above:
I tried adding the simple serialization code based on the boost site example
to my app and it crashes for both writing and reading the binary archive:
#include <string>
#include <vector>
#include <fstream>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/base_object.hpp>
using namespace std;
class gps_position
{
private:
friend class boost::serialization::access;
// When the class Archive corresponds to an output archive, the
// & operator is defined similar to <<. Likewise, when the class
Archive
// is a type of input archive the & operator is defined similar to >>.
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
for(int i = 0; i < 10; i++) {
ar & data[i];
}
}
int degrees;
int minutes;
float seconds;
double* data;
public:
gps_position(){};
gps_position(int d, int m, float s) :
degrees(d), minutes(m), seconds(s)
{
data = new double[10];
for(int i = 0; i < 10; i++) {
data[i] = i*0.1;
}
}
};
void boost2()
{
cout << "writing archive..." << endl;
std::ofstream bofs("gps.bin", std::ios::binary);
// create class instance
const gps_position g2(36, 60, 24.567f);
boost::archive::binary_oarchive oa(bofs);
oa << g2;
cout << "reading archive..." << endl;
gps_position newg;
// create and open an archive for input
std::ifstream ifs("gps.bin", std::ios::binary);
boost::archive::binary_iarchive ia(ifs);
// read class state from archive
ia >> newg;
cout << "done." << endl;
}
// calling boost2()
crashes - stack shown below:
> msvcr80d.dll!memcpy(unsigned char * dst=0xcdcdcdcd, unsigned char *
src=0x0012fb44, unsigned long count=1) Line 350 Asm
msvcr80d.dll!memcpy_s(void * dst=0xcdcdcdcd, unsigned int
sizeInBytes=3452816845, const void * src=0x0012fb44, unsigned int count=1)
Line 67 + 0x11 bytes C
msvcp80d.dll!std::char_traits<char>::_Copy_s(char * _First1=0xcdcdcdcd,
unsigned int _Size_in_bytes=3452816845, const char * _First2=0x0012fb44,
unsigned int _Count=1) Line 575 + 0x16 bytes C++
msvcp80d.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char
* _First1=0xcdcdcdcd, unsigned int _Size=3452816845, const char *
_First2=0x0012fb44, unsigned int _Count=1, std::_Secure_char_traits_tag
__formal={...}) Line 707 + 0x15 bytes C++
msvcp80d.dll!std::_Traits_helper::copy_s<std::char_traits<char> >(char
* _First1=0xcdcdcdcd, unsigned int _Size=3452816845, const char *
_First2=0x0012fb44, unsigned int _Count=1) Line 699 + 0x21 bytes C++
msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
>::assign(const
std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
> & _Right="*", unsigned int _Roff=0, unsigned int _Count=4294967295) Line
1021 + 0x25 bytes C++
msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
>::assign(const
std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
> & _Right="*") Line 1006 C++
msvcp80d.dll!std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
>::operator=(const
std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char>
> & _Right="*") Line 888 C++
msvcp80d.dll!std::_DebugHeapString::operator=(const
std::_DebugHeapString & __that={...}) + 0x13 bytes C++
evviewn.exe!std::locale::locale<boost::archive::codecvt_null<char>
>(const std::locale & _Loc={...}, const boost::archive::codecvt_null<char> *
_Facptr=0x028f42b8) Line 301 + 0x33 bytes C++
evviewn.exe!boost::archive::add_facet<boost::archive::codecvt_null<char>
>(const std::locale & l={...}, boost::archive::codecvt_null<char> *
f=0x028f42b8) Line 46 + 0x2a bytes C++
evviewn.exe!boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive,char,std::char_traits<char>
>::basic_binary_oprimitive<boost::archive::binary_oarchive,char,std::char_traits<char>
>(std::basic_streambuf<char,std::char_traits<char> > & sb={...}, bool
no_codecvt=false) Line 116 + 0x48 bytes C++
evviewn.exe!boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive,char,std::char_traits<char>
>::binary_oarchive_impl<boost::archive::binary_oarchive,char,std::char_traits<char>
>(std::basic_ostream<char,std::char_traits<char> > & os={...}, unsigned int
flags=0) Line 79 + 0x4d bytes C++
evviewn.exe!boost::archive::binary_oarchive::binary_oarchive(std::basic_ostream<char,std::char_traits<char>
> & os={...}, unsigned int flags=0) Line 38 + 0x17 bytes C++
evviewn.exe!boost2() Line 277 + 0x14 bytes C++
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