Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Advanced Tools Module User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

5.1 Introducing the Serialization Package

The Serialization package provides a way to flatten objects, so they can be easily transported across communication boundaries or stored to disk. This object serialization mechanism includes two processes:

The classes, macros, and functions in the Serialization package help you to define serializable objects with a minimum of custom code, while retaining control over the formats and policies used. To make your C++ classes serializable, you prepare them with a small set of streaming macros. These macros encapsulate the details associated with streaming protocols, shielding your application from the implementation details but otherwise not affecting your application code. You have a choice of intrusive serialization for your own classes or external serialization for classes that you can't modify, such as classes from a third-party library. The package also includes a set of utility functions for streaming objects to and from various formats.

5.1.1 Classes Supported by the Serialization Package

The Serialization package has built-in support for the following classes:

Collectable classes can be streamed out in the Rogue Wave persistence format, or in the format of a particular object stream. To stream a collectable class in Rogue Wave persistence format you only need to include the RWCollectableIO.h header file and define the macro RW_DEFINE_COLLECTABLE_AS_STREAMABLE(className) for the class (see Section 6.5.1, "Using Object Streams with RWCollectable-Derived Objects."). Now an object of this class will be embedded within the stream using the Rogue Wave persistence format (regardless of the format of the object stream itself). To stream out a collectable in the format for the object stream you are using you must declare RW_DECLARE_STREAMABLE_COLLECTABLE and then use the external serialization macros just as you would for a class from any other library (see Section 6.5.2, "Making RWCollectable Objects That Are Also Serializable.").

5.1.2 Object Serialization for Saving Program State

The most common use for object serialization is to save the state of a program to disk, so that the state can be restored when the program starts again. Rather than developing custom code and custom file formats to add this function to your application, you can use the Serialization package's tools and industry-standard formats.

5.1.3 Object Serialization and Distributed Applications

Object serialization is also useful for distributed applications. Often you run into the trade-off between passing a reference to a remote object from one process to another or passing the object itself between processes. If the objects are not large, have static state, and will be accessed often, you may decide to send them by value between processes. Rather than writing custom network protocols to transmit application objects and writing code to read and write these protocols, you can use the Serialization package, which transmits serialized objects as blocks of raw data using generic protocols.

5.1.4 Interpackage Dependencies

The Serialization package depends on the Streams package, as well as the Smart Pointer, Synchronization, Execution Tracing and Thread-compatible Exception packages of the Threads Module.



Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and SourcePro, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.