Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. boost serialization/deserialization strange problem

boost serialization/deserialization strange problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphicsjsonperformance
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dliviu
    wrote on last edited by
    #1

    hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:

    #include #include #include #include #include #include #include using namespace std;

    #define COUNT 26

    class person;

    vector v;

    class person

    {

    public:

    string _name;

    int _age;

    person (string name="Liviu", int age=40):_name(name),_age(age){};

    friend class boost::serialization::access;

    template void serialize(Archive & ar, const unsigned int version)

    {

    ar & _name;

    ar & _age;

    }

    };

    void save()

    {

    ofstream file("archiv.cst");

    boost::archive::binary_oarchive oa(file);

    for (int i=1; i<=COUNT; i++)

    {

    oa<>p;

    v.push_back(p);

    // cout << p._name<<" " <>i;

    while (i!=2)

    {

    if (i==0) save();

    if (i==1) load();

    cin>>i;

    }

    }

    Can you help me please? Is something wrong with the library?

    L A 2 Replies Last reply
    0
    • D dliviu

      hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:

      #include #include #include #include #include #include #include using namespace std;

      #define COUNT 26

      class person;

      vector v;

      class person

      {

      public:

      string _name;

      int _age;

      person (string name="Liviu", int age=40):_name(name),_age(age){};

      friend class boost::serialization::access;

      template void serialize(Archive & ar, const unsigned int version)

      {

      ar & _name;

      ar & _age;

      }

      };

      void save()

      {

      ofstream file("archiv.cst");

      boost::archive::binary_oarchive oa(file);

      for (int i=1; i<=COUNT; i++)

      {

      oa<>p;

      v.push_back(p);

      // cout << p._name<<" " <>i;

      while (i!=2)

      {

      if (i==0) save();

      if (i==1) load();

      cin>>i;

      }

      }

      Can you help me please? Is something wrong with the library?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Put your code inside a try{}catch{} block, and check which exception is being thrown.

      Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

      D 1 Reply Last reply
      0
      • L Lost User

        Put your code inside a try{}catch{} block, and check which exception is being thrown.

        Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

        D Offline
        D Offline
        dliviu
        wrote on last edited by
        #3

        the exception cannot be caught with a try - catch block i already told you what the exception is

        L 1 Reply Last reply
        0
        • D dliviu

          the exception cannot be caught with a try - catch block i already told you what the exception is

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          How else can you catch it? I would suggest that you try the boost website to see what you need to do.

          Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

          D 1 Reply Last reply
          0
          • L Lost User

            How else can you catch it? I would suggest that you try the boost website to see what you need to do.

            Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

            D Offline
            D Offline
            dliviu
            wrote on last edited by
            #5

            boost site sucks they have no forum

            L 1 Reply Last reply
            0
            • D dliviu

              boost site sucks they have no forum

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Did you look here[^]?

              Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

              D 1 Reply Last reply
              0
              • L Lost User

                Did you look here[^]?

                Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

                D Offline
                D Offline
                dliviu
                wrote on last edited by
                #7

                ok, thanks

                1 Reply Last reply
                0
                • D dliviu

                  hello I have installed boost 1.47.0 library on my system and I have a strange problem. If I try to serialize more then 25 objects, the serialization (save()) apparently works but the deserialization (load()) does not work anymore and it gives me the following error: Unhandled exception at 0x7c812afb in Boost_tests.exe: Microsoft C++ exception: boost::archive::archive_exception at memory location 0x0012e5ec.. this error is raised when the last object (say the 26th object, if the number of objects is higher then 25) is being deserialized. here is the code:

                  #include #include #include #include #include #include #include using namespace std;

                  #define COUNT 26

                  class person;

                  vector v;

                  class person

                  {

                  public:

                  string _name;

                  int _age;

                  person (string name="Liviu", int age=40):_name(name),_age(age){};

                  friend class boost::serialization::access;

                  template void serialize(Archive & ar, const unsigned int version)

                  {

                  ar & _name;

                  ar & _age;

                  }

                  };

                  void save()

                  {

                  ofstream file("archiv.cst");

                  boost::archive::binary_oarchive oa(file);

                  for (int i=1; i<=COUNT; i++)

                  {

                  oa<>p;

                  v.push_back(p);

                  // cout << p._name<<" " <>i;

                  while (i!=2)

                  {

                  if (i==0) save();

                  if (i==1) load();

                  cin>>i;

                  }

                  }

                  Can you help me please? Is something wrong with the library?

                  A Offline
                  A Offline
                  Albert Holguin
                  wrote on last edited by
                  #8

                  dliviu wrote:

                  for (int i=1; i<=COUNT; i++)   {   person p;   ia>>p;   v.push_back(p);   // cout << p._name<<" " <<p._age<<endl; }

                  When you do this... you're loading a stack variable into a dynamic heap object. The stack variable falls out of scope at the end of the execution of each for loop iteration. This isn't necessarily the problem causing the crash you're seeing, but it's definitely a problem. Correction: vector::push_back() does make a copy and not just keep the pointer.

                  D 1 Reply Last reply
                  0
                  • A Albert Holguin

                    dliviu wrote:

                    for (int i=1; i<=COUNT; i++)   {   person p;   ia>>p;   v.push_back(p);   // cout << p._name<<" " <<p._age<<endl; }

                    When you do this... you're loading a stack variable into a dynamic heap object. The stack variable falls out of scope at the end of the execution of each for loop iteration. This isn't necessarily the problem causing the crash you're seeing, but it's definitely a problem. Correction: vector::push_back() does make a copy and not just keep the pointer.

                    D Offline
                    D Offline
                    dliviu
                    wrote on last edited by
                    #9

                    I don't see any problem here. p is an object which when it is inserted in v it is copied. Anyway, this is not the problem. Boost library site sucks, and i have no solution to my strange problem. :(

                    A 1 Reply Last reply
                    0
                    • D dliviu

                      I don't see any problem here. p is an object which when it is inserted in v it is copied. Anyway, this is not the problem. Boost library site sucks, and i have no solution to my strange problem. :(

                      A Offline
                      A Offline
                      Albert Holguin
                      wrote on last edited by
                      #10

                      I had to look at the implementation of vector.. you're correct, it is copied. As far as the boost site sucking, well, that's something you have to live with when using third party libraries. You can always make your own serialization class and you won't have support issues (although it'll take you some time to do it).

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups