$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Tim Taylor (tim_at_[hidden])
Date: 2006-06-09 14:32:12
Hi Peter and Robert,
Many thanks for your replies.  Destroying the input archive solves the 
problem.
Best wishes,
Tim
Robert Ramey wrote:
> I'm concerned that the input put archive is not destroyed soon enough.
> It has to hold a copy of the shared pointer as long its open.  Try the 
> following
> changes: (I've simplified it a little)
> 
> int main(int argc, char **argv)
> {
>     const char *filename = "bag.ser";
>     {
>         const Bag b(shared_ptr<Item>(new Item(1)));
>         // now serialize the Bag
>         cout << "About to serialize bag..." << endl;
>         ofstream osSer(filename);
>         boost::archive::text_oarchive oa(osSer);
>         oa << b;
>         b.printUseCount();
>         cout << "About to delete bag 1..." << endl;
>     } // no need for stream close, archive and stream closed automatically
>     cout << "About to create a new bag..." << endl;
>     Bag b1;
>     {
>         b1.printUseCount();
>         // and deserialize it into the new Bag object
>         cout << "About to deserialize bag..." << endl;
>         ifstream isSer(filename, std::ios::binary);
>         boost::archive::text_iarchive ia(isSer);
>         ia >> b1;
>         b1.printUseCount(); // should equal 2 - b1 plus one in the archive
>     } // close all streams and archives
>     b1.printUseCount(); // should equal 1 - b1 plus one in the archive
>     return 0;
> }
> 
> 
> I haven't tested this - if it doesn't work as expected - my name is mud 
> here.
> 
> Robert Ramey 
> 
> 
> 
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://listarchives.boost.org/mailman/listinfo.cgi/boost-users
>