Boost logo

Boost Users :

Subject: Re: [Boost-users] [Serialization] Load an object from the base pointer
From: Ryan Fowler (Ryan.Fowler_at_[hidden])
Date: 2009-03-05 06:56:43


I've seen the following:

 

main(){

    ...

    base *b;

    ...

    ar & b;

}

 

But that doesn't quite help me. All of our objects come from a memory
pool and I either need to know ahead of time which object to allocate or
I need to pass an allocator to the archive so that it can get the memory
from the pool.

 

Are either of these possible? Also, in the above example, how does the
archive allocate the memory for 'b'? Does it use new? Or does it have
it's own pre-allocated store?

 

Thanks,

Ryan

 

From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Robert Ramey
Sent: 04 March 2009 17:30
To: boost-users_at_[hidden]
Subject: Re: [Boost-users] [Serialization] Load an object from the base
pointer

 

This is explained in the documentation and illustrated by the demos and
tests.

 

In fact, you can even build a progam which will be able to de-serialize
types included

in DLLS which have yet to be created.

 

Robert Ramey

        "Ryan Fowler" <Ryan.Fowler_at_[hidden]> wrote in message
news:1C50BA0DCB34A24E9C8ABA96570EF18F073F5211_at_LONSMSXM06.emea.ime.reuter
s.com...

        Hi,

         

        How can I read in a from a stream when I don't know the exact
type I will be getting? All objects I receive will derive from the same
base class, but I won't know when I receive the stream what the derived
type will be and therefore I can't create it in advance (like in the
docs).

         

        class base

        {

        ...

        }

         

        class derived1 : public base

        {

        ...

        }

         

        class derived2 : public base

        {

        ...

        }

         

        int main()

        {

            // Get a stream from somewhere

            boost::archive::binary_iarchive ia( instream );

         

            base b0;

            derived1 d1;

            derived2 d2;

            is >> // derived1 or derived2???

        }

         

        Ryan Fowler
        Software Engineer

        Thomson Reuters

        Phone: +442075427063

        ryan.fowler_at_[hidden]
        thomsonreuters.com

        
        This email was sent to you by Thomson Reuters, the global news
and information company.
        Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be the views
of Thomson Reuters.

        
________________________________

        _______________________________________________
        Boost-users mailing list
        Boost-users_at_[hidden]
        http://lists.boost.org/mailman/listinfo.cgi/boost-users

This email was sent to you by Thomson Reuters, the global news and information company.
Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters.



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