INFO: Archiving Several Objects That Point to a Third ObjectLast reviewed: October 10, 1997Article ID: Q85520 |
The information in this article applies to:
SUMMARYWhen an application uses the archiving capabilities of the Microsoft Foundation Classes, you must carefully archive objects that contain pointers. If two distinct objects (A and B) each point to a third object (C), you serialize A and B into separate archives, and deserialize A and B, each one points to a unique copy of object C. This can cause several problems. If either object A or B changes object C, the change affects only the corresponding copy of object C. This can cause inconsistencies. In addition, this creates duplicate copies of object C on disk and in memory which wastes system resources.
MORE INFORMATIONThe CArchive class provides a solution to this classic problem when an application serializes two objects into one archive object. Each archive maintains a mapping from the stored object to a 16-bit persistent identifier (PID). The serialization process assigns a new PID to each unique class and object name in an archive. Each time an application saves an object to the archive (usually through the insertion operator), the serialization code determines if the class or object already exists in the archive. For any class or object already in the archive, the code inserts the PID already associated with the object instead of a new copy of the class or object. PID values have no significance outside an archive. If you serialize objects A and B into different archives, the process assigns a PID to object C and stores of the object in each archive, even if both archives refer to the same file. Even if you disregard the space that this process wastes, deserializing the objects creates a data structure that contains two distinct copies of object C, which does not accurately reflect the original data structure. Additional information on storing objects using the CArchive class is available in the "Class Libraries User's Guide" and in the "Class Libraries Reference" manual. In Visual C++, further information is available in Technical Note #2 in the MFC Tech Notes help file. In Microsoft C/C++ version 7.0, further information is available in Microsoft Foundation Classes technical note file TN002.TXT. NOTE: Starting with Visual C 4.0, the PID can be 16- or 32-bit value depending on the number of objects serialized.
|
Additional query words: Carchive persistent serialize
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |