CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Posts
    117

    Table of contents when using ::Serialize()?

    Is it possible to set up a table of contents when working with ::Serialize()?

    For example, I have a savefile that contains 10.000 objects.
    The savefile is rather large, and if possible, I would only like to load specific objects from it.
    For example, I only want to load object #651 from the 10.000 objects in the file.

    Is there some way of specifying the location of each object in a savefile, and instructing Serialize to move to that location, and load only that specific object?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Table of contents when using ::Serialize()?

    I have no idea what (global) ::Serialize() function you meant, however you may want to have a look at the An Introduction to Object Serialization in C++ and this microsoft topic: Serialization: Making a Serializable Class
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2007
    Posts
    117

    Re: Table of contents when using ::Serialize()?

    My apologies, I probably didn't explain myself clearly.
    Let's say that I have 1000 objects.
    I want to store these objects in a savefile, using Serialize.

    The code for this will roughly be:

    Code:
    void MyDoc::Serialize(CArchive& ar)
    {
    	if (ar.IsStoring())
    	{
                 for(int i = 0; i < 1000; i++)m_MyObject[i].Serialize(ar);
            }
            else
           {
                 for(int i = 0; i < 1000; i++)m_MyObject[i].Serialize(ar);
           }
    }
    However, in the case that I'm looking at, these savefiles can become huge.
    They can be several GB.

    Because of this, I was wondering if it was possible to load a specific object from a savefile?

    So, let's say that I only want object target_nr = 365.

    The code for this would roughly be:

    Code:
    void MyDoc::Serialize(CArchive& ar, const int & target_nr)
    {
    	if (ar.IsStoring())
    	{
                 for(int i = 0; i < 1000; i++)m_MyObject[i].Serialize(ar);
            }
            else
           {
                 ar.MoveToLocation(365);
                 m_MyObject[target_nr].Serialize(ar);
           }
    }
    So, my question is, is it possible to instruct the CArchive to move to a specific location in the savefile, and only load a specific object?

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Table of contents when using ::Serialize()?

    That's what databases are for

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Table of contents when using ::Serialize()?

    I agree with GCDEF! Just use a database.
    Victor Nijegorodov

  6. #6
    Join Date
    Mar 2022
    Posts
    9

    Re: Table of contents when using ::Serialize()?

    Database, should solve your issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured