Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:47:58+00:00 2026-05-23T09:47:58+00:00

I use boost::serialization to save an object that contains this data : struct Container

  • 0

I use boost::serialization to save an object that contains this data :

struct Container
{
    struct SmallObject
    {
        struct CustomData
        {
            unsigned first;
            float second;
        };

        std::vector<CustomData> customData; // <- i can have 1 to 4 of these in the std::vector
        float data1[3];
        float data2[3];
        float data3[2];
        float data4[4];
    };

    std::vector<SmallObject> mySmallerObjects;  // <- i can have 8000 to 13000 of the std::vector
};

The serialization code looks like this (this in the intrusive version, I didn’t write the functions declaration above for readability purposes) :

template<class Archive> void Container::SmallObject::CustomData::serialize(Archive& ar, unsigned /*version*/)
{
    ar & first;
    ar & second;
}

template<class Archive> void Container::SmallObject::serialize(Archive& ar, unsigned /*version*/)
{
    ar & customData;
    ar & data1
    ar & data2;
    ar & data3;
    ar & data4;
}

template<class Archive> void Container::serialize(Archive& ar, unsigned /*version*/)
{
    ar & mySmallerObjects;
}

I use binary_archives. In release mode, loading my container (with 12000 small objects) takes about 400 milliseconds. I am told this is too long. Are there any settings or different memory layouts that would speed up the loading process ? Shall I giveup using boost::serialization ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:47:58+00:00Added an answer on May 23, 2026 at 9:47 am

    If I had to pick the single biggest drawback of Boost.Serialization, it would be poor performance. If 400ms is truly too slow, either get faster hardware or switch to a different serialization library.

    That said, just in case you’re doing something blatantly “wrong”, you should post the serialization code for Container, Container::SmallObject, and Container::SmallObject::CustomData. You should also ensure that it’s actually deserialization that’s taking 400ms, and not a combination of deserializing + reading the data from the disk; i.e., load the data into a memory-stream of some sort and deserialize from that, rather than deserializing from an std::fstream.


    EDIT (in response to comments):

    This code works for me using VC++ 2010 SP1 and Boost 1.47 beta:

    double loadArchive(std::string const& archiveFileName, Container& data)
    {
        std::ifstream fileStream(
            archiveFileName.c_str(),
            std::ios_base::binary | std::ios_base::in
        );
        std::stringstream buf(
            std::ios_base::binary | std::ios_base::in | std::ios_base::out
        );
        buf << fileStream.rdbuf();
        fileStream.close();
    
        StartCounter();
        boost::archive::binary_iarchive(buf) >> data;
        return GetCounter();
    }
    

    If this doesn’t work for you, it must be specific to the compiler and/or version of Boost you’re using (which are what?).

    On my machine, for an x86 release build (with link-time code generation enabled), loading the data from disk is ~9% of the overall time taken to deserialize a 1.28MB file (1 Container containing 13000 SmallObject instances, each containing 4 CustomData instances); for an x64 release build, loading the data from disk is ~17% of the overall time taken to deserialize a 1.53MB file (same object counts).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to use boost::serialization on XML archives. I can produce and read data,
I know that you can use boost serialization to serialize to a text format
I use Boost.Serialization to serialize a std::map. The code looks like this void Dictionary::serialize(std::string
Boost::Serialization has builtin support for boost::shared_ptr<> . Is there a way to use this
I use RCF with boost.serialization (why use RCF's copy when we already use the
I've used boost serialization but this doesn't appear to allow me to generate xml
Is it possible to use boost::fusion::invoke function to call a function that has default
I want to use a temp directory that will be unique to this build.
I'm trying to use boost::mpl::inherit_linearly to compose a container class using types provided by
so i use BOOST.EXTENTION to load modules. I have a special file that describes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.