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 6360501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:39:26+00:00 2026-05-24T23:39:26+00:00

Slightly related question to this one and this one . Basically, I would like

  • 0

Slightly related question to this one and this one.

Basically, I would like to serialize objects as they come, much like a log file, except that I want to unserialize them later. This means that I don’t have all the objects initially.

From previous answers, it looks like if one keeps the same archive open, one can keep on adding more and more objects to the archive.

But how would I extract them? Do I need to look ahead and see whether eof is reached before each extraction? Should I place a linebreak into the saving routine so that I can later read the input line by line (this would probably only work with binary archives (and maybe text), as xml uses linebreaks, and maybe not even there if binary might use a linebreak occasionally)? Maybe the >> operation throws an exception if the file end is reached and I can wrap it in an infinite loop with a try catch around it?

And how would I go about it if I wanted to do so for different kinds of objects? Maybe have an enum for all objects and serialize the enum just before, and on unserializing have a switch based on the enum?

Thanks

  • 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-24T23:39:26+00:00Added an answer on May 24, 2026 at 11:39 pm

    Here is what I did in the end. Since Nicol is right and this really is a bit of not-intended use, first one has to make sure to disable pointer tracking. Otherwise one gets spurious shared objects. Hence to begin with, loads of

    BOOST_CLASS_TRACKING(yourDerivedClass,boost::serialization::track_never)
    

    I also settled for just logging objects that derive from the same base object (you could just create an empty virtual base for this purpose). Once that is done, it is important to make sure it is seen as abstract (I made sure to have virtual destructors, and still added

    BOOST_SERIALIZATION_ASSUME_ABSTRACT(yourBaseClass)
    

    Register all derived classes with the archive after creating it (both write and read)

    arMsgs.template register_type<yourDerivedClass>();
    

    Only register final non abstract class (if A derives from B derives from C, don’t register B). At least any registered class needs to have tracking disabled.

    Finally add them to the archive as they come.

    To reload them, rather than using a special token for end of file, which would require checking, I went for

    try 
    {
        for(;;)
        {
            yourBaseClass obj;
            arObjs >> boost::serialization::make_nvp("Obj",obj);
            //your logic
        }
    }
    catch(boost::archive::archive_exception const& e) { }
    

    That might catch a bit too much, so might need some extra checks but this is working for me. The advantage is that a proper shut down isn’t as important, e.g. if your app crashes midway through, you can still process up to the last readable message.

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

Sidebar

Related Questions

Although slightly related to a previous question, it is different. How secure is this
I realize that this question is slightly server related and could be posted on
This question is related to this previous one on how to replace accented strings
Slightly related to this question , but you don't really need to read that.
This is perhaps related to this question , but I have slightly more information.
slightly related to this question here . My problem: I am writing a bit
[Disclosure: This question is slightly related to my previous question .] As you can
This is slightly related to the question asked here yet the answer does not
Slightly related to my other question : What is the difference between the following:
This is a slightly tricky question. I am using NSDateFormatter on the iPhone but

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.