Andrew Hundt | 1 Sep 03:25 2011
Picon

Re: [serialization] deserializing asynchronously serialized types

> Just use boost::variant. Serialization is already implemented for it > and it effectively does the above. It does a bunch of other stuff > as well which is likely useful for your application.
I've tried boost.variant with the full typelist, but it seems gcc 4.4 balks at typelists longer than 60, and I have over 104 types and growing. Perhaps there is some workaround for extremely long type list lengths that I'm not aware of?

Sorry I'm not below your message, I didn't get the email directly to my address so I'm not sure how to do it indirectly.

Cheers!
Andrew Hundt



On Tue, Aug 30, 2011 at 6:27 PM, Andrew Hundt <athundt <at> gmail.com> wrote:
I have an unusual use case for boost.serialization, and I was wondering if it would be possible to adapt it to my needs:

- I have a set of over 100 types, and instances of each are generated asynchronously then serialized to a file in that order. 
- The most interesting serialized data will be written just before the power is unexpectedly cut.
- I need to load in and run on as much data as possible when reading the serialized data back, ignoring incomplete data at the end (due to a power cut). 
- The basic Boost serialization examples require you to know the type of the next piece of data to be loaded when reading. Since these types are generated asynchronously they are not known in advance.  
- I need to write the data out immediately when it arrives because of the power issue. 
- Files will be getting up to around 150GB in size for binary archives, so it can't be marshaled in memory, it needs to be written immediately even if it is redundant.

Is there a way to read in that serialized file using the facilities provided in boost.serialization?

I could also serialize an index or custom headers indicating the next type to appear, I would prefer to avoid doing so.

One way of achieving some of these goals is writing one piece at a time using a binary archive to an fstream. But I don't know what aspects of my requirements will prove to be a problem.

Thanks for your thoughts.

Cheers!
Andrew Hundt


_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
egoots | 1 Sep 07:40 2011
Picon

Re: complex matrix operations

On 8/31/2011 6:04 AM, sairamesh raghuraman wrote:
...
> I have already found a library that can do all of the above..used it..it
> works fine..but a disadvantage is that it cannot handle multidimensional
> arrays.

Out of curiosity and in case it is relevant for a reply, what library 
are you using?

eg
Thomas Heller | 1 Sep 08:43 2011

Re: [bind] deduce arguments types

On Thursday, September 01, 2011 12:15:12 AM Martin Häfner wrote:
> Hi all,
<snip>
> The problem now is that I want to deduce the result type of the given
> actor as well as the argument type. Retrieving the result type is
> manageable with boost binders but I have no idea how I could retrieve
> the argument type in order to do a proper conversion from char* to int
> without the usage of make_adaptable<> which breaks the elegance of the
> binder usage at this point.
> 
> My self-written binder class exposes appropriate typedefs so the
> writer of the parser grammar does not have to cope with all that
> 'magic' template stuff, but I cannot get a working solution for
> boost::bind nor do I get a working solution with tr1 binders.
> 
> Maybe anybody could help or at least could explain me why the boost
> classes do not define these simple typedefs?

You lost me. The type of the arguments isn't known until the bound function is 
called. That is, for example, if you have a placeholder inside your bind 
expression, what would that type be? And this is one of the easier usecases 
... It gets more complicated once you have nested calls to bind, or use some 
operators.

You might want to look into Phoenix. Phoenix lets you introspect the passed 
lambda with proto.

> Regards,
> Martin
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Alessandro Candini | 1 Sep 09:03 2011
Picon

Re: Asio example 5 sagmentation fault

On 31/08/11 21:10, Anthony Foiani wrote:
> Alessandro, greetings --
>
> Alessandro Candini<candini <at> meeo.it>  writes:
>
>> I'm really interested in exemple 5 of boost asio:
>>
>> http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/tutorial/tuttimer5/src.html
>>
>> I've tried it with boost-1.47.0. I can compile without warnings using:
>>
>> g++ -Wall -pedantic -lboost_thread -lboost_system -o timer5 timer5.cpp
>>
>> but when I launch the executable it gives me a Segmentation fault.
>>
>> Commenting the code I found that the segmentation fault raise at the
>> 3rd line of main:
>>
>> boost::thread t(boost::bind(&boost::asio::io_service::run,&io));
>>
>> I'm trying on the following machine:
>> Linux office-007 2.6.38-11-generic #48-Ubuntu SMP Fri Jul 29 19:02:55
>> UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
> Not exactly the same setup, but on a very current gcc+boost on a
> similar system, it seems to work fine:
>
>    $ uname -a
>    Linux foo 2.6.35.14-95.fc14.x86_64 #1 SMP \
>      Tue Aug 16 21:01:58 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
>
>    $ g++ -v
>    Using built-in specs.
>    COLLECT_GCC=g++
>    COLLECT_LTO_WRAPPER=/usr/local/gcc-4.6.1/libexec/gcc/x86_64-unknown-linux-gnu/4.6.1/lto-wrapper
>    Target: x86_64-unknown-linux-gnu
>    Configured with: ../gcc-4.6.1/configure --prefix=/usr/local/gcc-4.6.1 \
>      --with-local-prefix=/usr/local/gcc-4.6.1/local \
>      --enable-languages=c,c++ --enable-threads
>    Thread model: posix
>    gcc version 4.6.1 (GCC)
>
>    $ g++ -Wall -pedantic -I/usr/local/boost/include \
>        -o boost-asio-segv boost-asio-segv.cpp \
>        -L /usr/local/boost/lib -lboost_thread -lboost_system
>
>    $ export LD_LIBRARY_PATH=/usr/local/gcc/lib64:/usr/local/boost/lib
>
>    $ ./boost-asio-segv
>    Timer 1: 0
>    Timer 2: 1
>    Timer 1: 2
>    Timer 2: 3
>    Timer 1: 4
>    Timer 2: 5
>    Timer 1: 6
>    Timer 2: 7
>    Timer 1: 8
>    Timer 2: 9
>    Final count is 10
>
>    $ ldd ./boost-asio-segv
>    linux-vdso.so.1 =>   (0x00007fffefda7000)
>    libboost_thread.so.1.47.0 =>  /usr/local/boost/lib/libboost_thread.so.1.47.0 (0x00007f7898f96000)
>    libboost_system.so.1.47.0 =>  /usr/local/boost/lib/libboost_system.so.1.47.0 (0x00007f7898d92000)
>    libstdc++.so.6 =>  /usr/local/gcc/lib64/libstdc++.so.6 (0x00007f7898a8e000)
>    libm.so.6 =>  /lib64/libm.so.6 (0x0000003da1a00000)
>    libgcc_s.so.1 =>  /usr/local/gcc/lib64/libgcc_s.so.1 (0x00007f789885a000)
>    libc.so.6 =>  /lib64/libc.so.6 (0x0000003da1200000)
>    libpthread.so.0 =>  /lib64/libpthread.so.0 (0x0000003da1600000)
>    librt.so.1 =>  /lib64/librt.so.1 (0x0000003da2200000)
>    /lib64/ld-linux-x86-64.so.2 (0x0000003da0e00000)
>
> You might want to try using 'ldd' to make sure that it's pulling in a
> consistent set of libraries (no 32/64 mismatch, no boost version
> mismatch, etc).
>
> Finally, use 'gdb' to see what is in "io" just before the segv.  Just
> looking at that line, I don't see how either of those addresses could
> be null, which would be the usual cause of a segv.  Maybe something
> like:
>
>    void * run_addr = static_cast<  void *>(&boost::asio::io_service_run );
>    void * io_addr  = static_cast<  void *>(&io );
>
> And see if either of those are null?
>
> If you have the resources, can you try building your own g++ and
> boost, to see if it works under that combination?
>
> If you still can't solve it, can you make sure to post the version of
> g++ that you're using?
>
>> "WARNING:This message contains confidential and/or proprietary
>> information which may be subject to privilege or immunity and which
>> is intended for use of its addressee only. Should you receive this
>> message in error, you are kindly requested to inform the sender and
>> to definitively remove it from any paper or electronic format."
> And this sort of thing is pretty useless / rude on a public mailing
> list, don't you think?
>
> Best regards,
> Tony
>
> p.s. I could also get the exact same source code to run under the
>       "stock" install on up-to-date Fedora 14, which means g++ 4.5.1
>       and boost 1.44.0:
>
>    $ unset LD_LIBRARY_PATH
>
>    $ g++ -Wall -pedantic -o boost-asio-segv boost-asio-segv.cpp \
>        -lboost_thread-mt -lboost_system-mt
>
>    $ ./boost-asio-segv
>    Timer 1: 0
>    Timer 2: 1
>    Timer 1: 2
>    Timer 2: 3
>    Timer 1: 4
>    Timer 2: 5
>    Timer 1: 6
>    Timer 2: 7
>    Timer 1: 8
>    Timer 2: 9
>    Final count is 10
>
>    $ rpm -q gcc boost-thread
>    gcc-4.5.1-4.fc14.x86_64
>    boost-thread-1.44.0-8.fc14.x86_64
I have gcc-4.5.2 instead of 4.6.1, but this is not the problem.
Now it works: the problem was indeed a link to old boost-1.42, not yet 
removed from my system.

Here's my steps to get it work:
$ make
g++ -Wall -pedantic -I/usr/local/include/boost -L /usr/local/lib 
-lboost_thread -lboost_system -o timer5 timer5.cpp

$ ldd timer5
     linux-vdso.so.1 =>  (0x00007ffff634e000)
     libboost_thread.so.1.47.0 => 
/usr/local/lib/libboost_thread.so.1.47.0 (0x00007fe590190000)
     libboost_system.so.1.47.0 => 
/usr/local/lib/libboost_system.so.1.47.0 (0x00007fe58ff8c000)
     libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 
(0x00007fe58fc85000)
     libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe58fa00000)
     libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 
(0x00007fe58f7ea000)
     libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe58f455000)
     libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 
(0x00007fe58f237000)
     librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe58f02f000)
     /lib64/ld-linux-x86-64.so.2 (0x00007fe5903dd000)

$ ./timer5
Timer 1: 0
Timer 2: 1
Timer 1: 2
Timer 2: 3
Timer 1: 4
Timer 2: 5
Timer 1: 6
Timer 2: 7
Timer 1: 8
Timer 2: 9
Final count is 10

Thank you so much!

-- 
Alessandro Candini

MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it

========================================
"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."
Lloyd | 1 Sep 09:27 2011
Picon

64bit boost::regex link error

Hi,

I am trying to port a 32bit  application built on 32bit windows to
64bit. We are using boost::regex library. We have successfully built
64 bit version of boost. When we try to link our application with
boost::regex we get the following error. What could be the reason?

We are using MS Windows 7 64bit, MS Visual studio 2010, and boost 1.46.1

This is the how we built boost

# bjam --build-type=minimal --with-regex  --address-model=64

This is the error reported.

myfile.obj : error LNK2001: unresolved external symbol "private: class
boost::basic_regex<char,struct boost::regex_traits<char,class
boost::w32_regex_traits<char> > > & __cdecl
boost::basic_regex<char,struct boost::regex_traits<char,class
boost::w32_regex_traits<char> > >::do_assign(char const *,char const
*,unsigned int)"
(?do_assign <at> ?$basic_regex <at> DU?$regex_traits <at> DV?$w32_regex_traits <at> D <at> boost <at>  <at>  <at> boost <at>  <at>  <at> boost <at>  <at> AEAAAEAV12 <at> PEBD0I <at> Z)

myfile.obj : error LNK2001: unresolved external symbol "private: void
__cdecl boost::re_detail::perl_matcher<char const *,class
std::allocator<struct boost::sub_match<char const *> >,struct
boost::regex_traits<char,class boost::w32_regex_traits<char> >
>::construct_init(class boost::basic_regex<char,struct
boost::regex_traits<char,class boost::w32_regex_traits<char> > > const
&,enum boost::regex_constants::_match_flags)"
(?construct_init <at> ?$perl_matcher <at> PEBDV?$allocator <at> U?$sub_match <at> PEBD <at> boost <at>  <at>  <at> std <at>  <at> U?$regex_traits <at> DV?$w32_regex_traits <at> D <at> boost <at>  <at>  <at> boost <at>  <at>  <at> re_detail <at> boost <at>  <at> AEAAXAEBV?$basic_regex <at> DU?$regex_traits <at> DV?$w32_regex_traits <at> D <at> boost <at>  <at>  <at> boost <at>  <at>  <at> 3 <at> W4_match_flags <at> regex_constants <at> 3 <at>  <at> Z)

myfile.obj : error LNK2001: unresolved external symbol "public: bool
__cdecl boost::re_detail::perl_matcher<char const *,class
std::allocator<struct boost::sub_match<char const *> >,struct
boost::regex_traits<char,class boost::w32_regex_traits<char> >
>::find(void)" (?find <at> ?$perl_matcher <at> PEBDV?$allocator <at> U?$sub_match <at> PEBD <at> boost <at>  <at>  <at> std <at>  <at> U?$regex_traits <at> DV?$w32_regex_traits <at> D <at> boost <at>  <at>  <at> boost <at>  <at>  <at> re_detail <at> boost <at>  <at> QEAA_NXZ)

Thanks,
   Lloyd
Martin B. | 1 Sep 09:39 2011
Picon
Picon

[test] Organizing C++ Unit Test code for maximum Unit Test efficiency?

Hi!

Recently asked a questing on SE

http://programmers.stackexchange.com/questions/105012/how-should-c-unit-test-code-be-organized-for-maximum-unit-test-efficiency

that boils down to

   How can C++ Unit Test code be effectively organized,
   so that it's both efficient
   to edit the (test) code
   and to run the test code?

I figured this might be of interest to Boot.Test users.

cheers,
Martin
Alessandro Candini | 1 Sep 14:13 2011
Picon

Re: [Threads] How to keep number of running thread constant, performing different operations

I've tryed implementing your suggestions with the following code:

#include <iostream>
#include </usr/local/include/boost/asio.hpp>
#include </usr/local/include/boost/thread/thread.hpp>
#include </usr/local/include/boost/bind.hpp>
#include </usr/local/include/boost/date_time/posix_time/posix_time.hpp>
#include </usr/local/include/boost/scoped_ptr.hpp>

void handler1()
{
     unsigned short int i;

     std::cout << "O--> Handler 1 <--O" << std::endl;
     for(i=0; i<65000; i++);
     std::cout << "X--> Handler 1 <--X" << std::endl;
}

void handler2()
{
     unsigned short int i;

     std::cout << "O--> Handler 2 <--O" << std::endl;
     for(i=0; i<1000; i++);
     std::cout << "X--> Handler 2 <--X" << std::endl;
}
int main()
{
     unsigned short nProc,
                i;
     boost::asio::io_service io;
     boost::scoped_ptr<boost::asio::io_service::work> work(new 
boost::asio::io_service::work(io));

     boost::thread_group tg;
     nProc = boost::thread::hardware_concurrency();

     for(i=0; i<nProc; ++i)
         tg.create_thread(boost::bind(&boost::asio::io_service::run, 
boost::ref(io)));

     io.post(handler2);
     io.post(handler1);
     io.post(handler2);
     io.post(handler2);
     io.post(handler2);
     io.post(handler2);
     io.post(handler2);
     io.post(handler2);
     io.post(handler2);
     io.post(handler1);
     io.post(handler2);

     work.reset();
     tg.join_all();

     return 0;
}

It seems to work, but it is correct, in your opinion?
The only problem is that it seems to never stop if I increase the value 
of i in handler1 up to 70000.
Have you any other suggestions?

-- 
Alessandro Candini

MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it

========================================
"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."
niXman | 1 Sep 14:33 2011
Picon

Re: [Threads] How to keep number of running thread constant, performing different operations

"unsigned short int i;" - is 16bit variable.
see here: http://liveworkspace.org/code/b88123920e184955e61aee9cc0c217c6

i.e. in your code variable "i" is overflowed.

2011/9/1 Alessandro Candini <candini <at> meeo.it>:
> I've tryed implementing your suggestions with the following code:
>
> #include <iostream>
> #include </usr/local/include/boost/asio.hpp>
> #include </usr/local/include/boost/thread/thread.hpp>
> #include </usr/local/include/boost/bind.hpp>
> #include </usr/local/include/boost/date_time/posix_time/posix_time.hpp>
> #include </usr/local/include/boost/scoped_ptr.hpp>
>
> void handler1()
> {
>    unsigned short int i;
>
>    std::cout << "O--> Handler 1 <--O" << std::endl;
>    for(i=0; i<65000; i++);
>    std::cout << "X--> Handler 1 <--X" << std::endl;
> }
>
> void handler2()
> {
>    unsigned short int i;
>
>    std::cout << "O--> Handler 2 <--O" << std::endl;
>    for(i=0; i<1000; i++);
>    std::cout << "X--> Handler 2 <--X" << std::endl;
> }
> int main()
> {
>    unsigned short nProc,
>               i;
>    boost::asio::io_service io;
>    boost::scoped_ptr<boost::asio::io_service::work> work(new
> boost::asio::io_service::work(io));
>
>    boost::thread_group tg;
>    nProc = boost::thread::hardware_concurrency();
>
>    for(i=0; i<nProc; ++i)
>        tg.create_thread(boost::bind(&boost::asio::io_service::run,
> boost::ref(io)));
>
>
>    io.post(handler2);
>    io.post(handler1);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler2);
>    io.post(handler1);
>    io.post(handler2);
>
>    work.reset();
>    tg.join_all();
>
>    return 0;
> }
>
> It seems to work, but it is correct, in your opinion?
> The only problem is that it seems to never stop if I increase the value of i
> in handler1 up to 70000.
> Have you any other suggestions?
>
> --
> Alessandro Candini
>
> MEEO S.r.l.
> Via Saragat 9
> I-44122 Ferrara, Italy
> Tel: +39 0532 1861501
> Fax: +39 0532 1861637
> http://www.meeo.it
>
> ========================================
> "ATTENZIONE:le informazioni contenute in questo messaggio sono
> da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
> al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
> per errore è tenuto ad informare il mittente ed a rimuoverlo
> definitivamente da ogni supporto elettronico o cartaceo."
>
> "WARNING:This message contains confidential and/or proprietary
> information which may be subject to privilege or immunity and which
> is intended for use of its addressee only. Should you receive this
> message in error, you are kindly requested to inform the sender and
> to definitively remove it from any paper or electronic format."
>
> _______________________________________________
> Boost-users mailing list
> Boost-users <at> lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Shipa | 1 Sep 14:36 2011
Picon

problem deserializing to base class pointer

I have a strange problem. 

I searched through the list and modified my initial code
quite a bit but cannot seem to get this to work. Serialization 
seems fine, but deserialization to base pointer in particular 
doesn't seem to work correctly (I am getting instance of base 
class inside). 

The example below is canonical version of a much more complex 
case I was working with, involving shared_ptr and template 
classes, but it boiled down (for now) to this:

A.h
----------------------------------------------------
#pragma once

#include "boost/serialization/serialization.hpp"
#include "boost/shared_ptr.hpp"

class A
{
public:
	int t;
	A():t(0){};

	//friend std::ostream& operator<<(std::ostream& os, const A& a);

	virtual ~A(){	};

	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & t;
	}
};

std::ostream& operator<<(std::ostream& os, const A& a)
{
	return os << "A: t = " << a.t << std::endl;
}

typedef boost::shared_ptr<A> APtr;
----------------------------------------------------

B.h
----------------------------------------------------

#pragma once

#include "boost/serialization/serialization.hpp"
#include "boost/shared_ptr.hpp"

class B: public A
{
public:
	int m;
	B():A(),m(0){};
	~B(){};

	//friend std::ostream& operator<<(std::ostream& os, const B& b);

	friend class boost::serialization::access;
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version)
	{
		ar & boost::serialization::base_object<A>(*this);
		ar & m;
	}
};

std::ostream& operator<<(std::ostream& os, const B& b)
{
	return os <<  "B: t = "<< b.t << "; m = "<< b.m << std::endl;
}

typedef boost::shared_ptr<B> BPtr;

----------------------------------------------------------------

Test.cpp
----------------------------------------------------------------
#include "stdafx.h"
#include "boost/shared_ptr.hpp"

#include "boost/serialization/shared_ptr.hpp"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/export.hpp>

#include <istream>
#include <ostream>
#include <fstream>

#include "A.h"
#include "B.h"

BOOST_CLASS_EXPORT(A)
BOOST_CLASS_EXPORT(B)

boost::archive::text_iarchive* GetiArchiveAndRegister(std::ifstream& f)
{
	boost::archive::text_iarchive* ar=
          new boost::archive::text_iarchive(f);
// 	ar->register_type(static_cast<A *>(NULL));
// 	ar->register_type(static_cast<B *>(NULL));
	return ar;
}

boost::archive::text_oarchive* GetoArchiveAndRegister(std::ofstream& f)
{
	boost::archive::text_oarchive* ar=new boost::archive::text_oarchive(f);
// 	ar->register_type(static_cast<A*>(NULL));
// 	ar->register_type(static_cast<B*>(NULL));
	return ar;
}

int _tmain(int argc, _TCHAR* argv[])
{
	A* a=new A();
	a->t=1;

	B* b=new B();
	b->t=2;
	b->m=1;

	A* c=new B();
	c->t=2;
	
	std::ofstream f1("c:\\a");
	boost::archive::text_oarchive* oa1=GetoArchiveAndRegister(f1);
	*oa1 & a;
	f1.close();

	std::ofstream f2("c:\\b");
	boost::archive::text_oarchive* oa2=GetoArchiveAndRegister(f2);
	*oa2 & b;
	f2.close();

	std::ofstream f3("c:\\c");
	boost::archive::text_oarchive* oa3=GetoArchiveAndRegister(f3);
	*oa3 & c;
	f3.close();

//deserializes fine
	std::ifstream f4("c:\\a");
	boost::archive::text_iarchive* oa4=GetiArchiveAndRegister(f4);
	*oa4 & a;
	f4.close();

//deserializes an instance of A
	std::ifstream f5("c:\\b");
	boost::archive::text_iarchive* oa5=GetiArchiveAndRegister(f5);
	*oa5 & a;
	f5.close();

//deserializes fine
	std::ifstream f6("c:\\c");
	boost::archive::text_iarchive* oa6=GetiArchiveAndRegister(f6);
	*oa6 & a;
	f6.close();

//deserializes fine
	std::ifstream f7("c:\\b");
	boost::archive::text_iarchive* oa7=GetiArchiveAndRegister(f7);
	*oa7 & b;
	f7.close();

	std::ifstream f8("c:\\c");
	boost::archive::text_iarchive* oa8=GetiArchiveAndRegister(f8);
//runtime error: vector subscript out of range on the next line
	*oa8 & b;
	f8.close();

	return 0;
}
------------------------------------------------------------------

deserializations of f5 and f8 are controversial.

I tried exchanging BOOST_CLASS_EXPORT calls with register_type 
call (commented out in GetiArchiveAndRegister and 
GetoArchiveAndRegister), and when that is done both 
serialization and deserialization finish correctly.

I tried changing the order of includes, moving BOOST_CLASS_EXPORT 
around, etc. This version is what I'm settled for as the correct 
one. 

What am I doing wrong? Can anybody help?
Robert Ramey | 1 Sep 19:11 2011

Re: problem deserializing to base class pointer

Shipa wrote:
> I have a strange problem.
>
> I searched through the list and modified my initial code
> quite a bit but cannot seem to get this to work. Serialization
> seems fine, but deserialization to base pointer in particular
> doesn't seem to work correctly (I am getting instance of base
> class inside).
>
> The example below is canonical version of a much more complex
> case I was working with, involving shared_ptr and template
> classes, but it boiled down (for now) to this:
>

...
> std::ofstream f2("c:\\b");
> boost::archive::text_oarchive* oa2=GetoArchiveAndRegister(f2);
> *oa2 & b;
> f2.close();
...
> //deserializes an instance of A
> std::ifstream f5("c:\\b");
> boost::archive::text_iarchive* oa5=GetiArchiveAndRegister(f5);
> *oa5 & a;
> f5.close();

...

> What am I doing wrong? Can anybody help?

Note violation of fundamental rule.  You have to deserialize the same type
you serialized.  Here we have:

oa << b
...
ia >> a

This cannot be expected to work.   You could do the following

oa << statiic_cast<a &>(b);
...
ia >> a;

I didn't look at f8.

Robert Ramey

Gmane