Serialization and raw pointer arrays
Hi,
I've inherited some complex math code that makes large usage of Matrices
based on raw pointer arrays. I need to serialize/deserialize these arrays
as is and am looking to use boost::serialization package. My attempt at
doing so results in the following errors (mostly about non integral array
size). As I do not know the array size when it is created (and lots of code
accesses the pointer directly as a chunk of memory that has been allocated,
what are my options to get this to work?
Errors:
/usr/include/boost/archive/detail/oserializer.hpp: In function `void
boost::archive::save(Archive&, T&) [with Archive =
boost::archive::text_oarchive, T = Dummy]':
/usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from
`void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int)
[with T = Dummy, Archive = boost::archive::text_oarchive]'
/usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated
from `Archive&
boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T
= Dummy, Archive = boost::archive::text_oarchive]'
serialize_array.cpp:56: instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:567: error: incomplete
type `boost::STATIC_ASSERTION_FAILURE< false>' used in nested name specifier
/usr/include/boost/archive/detail/oserializer.hpp:567: error: size of array
has non-integral type `<type error>'
Code:
#include
Hi Eric, See inline below, which compiles for me. Eric wrote:
Hi, I've inherited some complex math code that makes large usage of Matrices based on raw pointer arrays. I need to serialize/deserialize these arrays as is and am looking to use boost::serialization package. My attempt at doing so results in the following errors (mostly about non integral array size). As I do not know the array size when it is created (and lots of code accesses the pointer directly as a chunk of memory that has been allocated, what are my options to get this to work?
I'm not sure what you're saying here, but to get your code to compile see the inline addition/changes below
Errors: /usr/include/boost/archive/detail/oserializer.hpp: In function `void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = Dummy]': /usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from `void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = Dummy, Archive = boost::archive::text_oarchive]' /usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from `Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = Dummy, Archive = boost::archive::text_oarchive]' serialize_array.cpp:56: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE< false>' used in nested name specifier /usr/include/boost/archive/detail/oserializer.hpp:567: error: size of array has non-integral type `<type error>'
Code: #include
#include <fstream> #include <iostream> #include
#include using namespace std; class Dummy {
BOOST_SERIALIZATION_SPLIT_MEMBER()
public: friend class boost::serialization::access;
Dummy() {pVal=NULL;size=0;} ~Dummy() {delete [] pVal;}
template<class Archive> void save(Archive & ar, const unsigned int version) const { ar & size; for (int i=0; i
template<class Archive> void load(Archive & ar, const unsigned int version) { ar & size; pVal = new int[size]; for (int i=0; i
int* pVal; int size; }; BOOST_CLASS_VERSION(Dummy, 1)
int main(int argc, char** argv) { Dummy d; d.size = 5; d.pVal = new int[d.size]; for (int i=0; i< d.size; i++) { d.pVal[i] = i+10; }
ofstream ofOut("testSer.txt"); { boost::archive::text_oarchive oa(ofOut); oa << d;
This is the 'const' problem many run into. Robert should really add this
as a FAQ entry! I've found two options available:
oa & d;
or
oa << const_cast
}
Dummy load; { ifstream ifIn("testSer.txt"); boost::archive::text_iarchive ia(ifIn); ia >> load; } cout << "size="<
for (int i=0; i< load.size; i++) { cout << load.pVal[i] <
return -1; }
Thanks, Eric
Jeff Flinn
Thanks Jeff, that fixed the issue. ________________________________ From: boost-users-bounces@lists.boost.org on behalf of Jeff Flinn Sent: Tue 10/30/2007 7:18 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Serialization and raw pointer arrays Hi Eric, See inline below, which compiles for me. Eric wrote:
Hi, I've inherited some complex math code that makes large usage of Matrices based on raw pointer arrays. I need to serialize/deserialize these arrays as is and am looking to use boost::serialization package. My attempt at doing so results in the following errors (mostly about non integral array size). As I do not know the array size when it is created (and lots of code accesses the pointer directly as a chunk of memory that has been allocated, what are my options to get this to work?
I'm not sure what you're saying here, but to get your code to compile see the inline addition/changes below
Errors: /usr/include/boost/archive/detail/oserializer.hpp: In function `void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = Dummy]': /usr/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from `void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = Dummy, Archive = boost::archive::text_oarchive]' /usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from `Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = Dummy, Archive = boost::archive::text_oarchive]' serialize_array.cpp:56: instantiated from here /usr/include/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE< false>' used in nested name specifier /usr/include/boost/archive/detail/oserializer.hpp:567: error: size of array has non-integral type `<type error>'
Code: #include
#include <fstream> #include <iostream> #include
#include using namespace std; class Dummy {
BOOST_SERIALIZATION_SPLIT_MEMBER()
public: friend class boost::serialization::access;
Dummy() {pVal=NULL;size=0;} ~Dummy() {delete [] pVal;}
template<class Archive> void save(Archive & ar, const unsigned int version) const { ar & size; for (int i=0; i
template<class Archive> void load(Archive & ar, const unsigned int version) { ar & size; pVal = new int[size]; for (int i=0; i
int* pVal; int size; }; BOOST_CLASS_VERSION(Dummy, 1)
int main(int argc, char** argv) { Dummy d; d.size = 5; d.pVal = new int[d.size]; for (int i=0; i< d.size; i++) { d.pVal[i] = i+10; }
ofstream ofOut("testSer.txt"); { boost::archive::text_oarchive oa(ofOut); oa << d;
This is the 'const' problem many run into. Robert should really add this
as a FAQ entry! I've found two options available:
oa & d;
or
oa << const_cast
}
Dummy load; { ifstream ifIn("testSer.txt"); boost::archive::text_iarchive ia(ifIn); ia >> load; } cout << "size="<
for (int i=0; i< load.size; i++) { cout << load.pVal[i] <
return -1; }
Thanks, Eric
Jeff Flinn _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Eric
-
Eric Melin
-
Jeff Flinn