Object Persistence

Class CObject, in conjunction with class CArchive, supports “object persistence” through a process called “serialization.” Object persistence allows you to save a complex network of objects in a permanent binary form (usually disk storage) that persists after those objects are deleted from memory. Later you can load the objects from persistent storage and “reconstitute” them in memory.

Serialization is not random access, but rather sequential. A group of objects is written to an archive, which is associated with an individual CFile object. If the objects to be serialized are contained in a collection, then a single Serialize call for the collection object results in the serialization of the whole collection, even if it contains nested objects or heterogeneous object collections. For a good example of collection serialization, see the tutorial in the Class Libraries User's Guide.

When you create your own serializable CObject-derived class, you must use the DECLARE_SERIAL macro in the class declaration, and you must use the IMPLEMENT_SERIAL macro in the class implementation. If you have added new data members in your derived class, you must override the base class Serialize member function to store object data to the archive and load object data from it.

Like the iostream classes, CArchive provides insertion (<<) and extraction (>>) operators.