$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] Boost::serialization problem when use archive in a loop
From: johann (jgoetz_at_[hidden])
Date: 2011-04-27 09:55:26
Just to let you know, I do not see the same behavior (I have cleaned up the
code and added the header files).
Here is the compilation command and output I get:
>g++ test.cpp -otest -lboost_serialization
>./test
serialize: 0.11
serialize: 0.12
serialize: 0.11
serialize: 0.11
serialize: 0.12
serialize: 0.11
serialize: 0.12
serialize: 0.11
serialize: 0.12
...
/// BEGIN file: test.cpp
#include <fstream>
#include <iostream>
#include <vector>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/timer.hpp>
using namespace std;
using namespace boost;
class NODE
{
  public:
    NODE(){}
    NODE* add(NODE* node)
    {
        children.push_back(node);
        return node;
    }
    ~NODE()
    {
        vector<NODE*>::const_iterator it;
        for(it = children.begin();
            it != children.end();
            ++it)
        {
            delete *it;
        }
    }
    vector<NODE*> children;
  private:
    friend class serialization::access;
    template <typename Archive>
    void serialize(Archive &ar, const unsigned int version)
    {
        ar & children;
    }
};
void save(NODE* main)
{
    ofstream stream("archive.tmp", ios::binary);
    archive::binary_oarchive oa(stream, archive::no_header);
    oa << main;
}
int main()
{
    timer t;
    NODE* main(new NODE());
    for (int i=0; i<2000;i++)
    {
        NODE* subnode = main->add( new NODE());
        for (int k=0; k<20; k++)
        {
            subnode->add( new NODE());
        }
    }
    for (int i=0; i<100; i++)
    {
        t.restart();
        save(main);
        cout<<"serialize: "<<t.elapsed()<<endl;
    }
    delete main;
    return 0;
}
/// EOF
-- View this message in context: http://boost.2283326.n4.nabble.com/Boost-serialization-problem-when-use-archive-in-a-loop-tp3463193p3478195.html Sent from the Boost - Users mailing list archive at Nabble.com.