beautypg.com

Simple persistence, Two examples of simple persistence – HP Integrity NonStop J-Series User Manual

Page 174

background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

Simple Persistence

Simple persistence is the storage and retrieval of an object to and from a stream. Table 1 lists the
classes in Tools.h++ that use simple persistence.

Category

Description

C++ fundamental types

int, char, float, ...

Rogue Wave date and time classes

RWDate

,

RWTime

Rogue Wave string classes

RWCString

,

RWWString

Miscellaneous Rogue Wave classes

RWBitVec

Because it is straightforward, simple persistence is a quick and easy way to save and restore
objects that have neither pointers to other objects nor virtual member functions.

However, when objects that refer to each other are saved and then restored with simple
persistence, the pointer relationships, or morphology, among the objects can change. This is
because simple persistence assumes that every pointer reference to an object in memory refers to
a unique object
. Thus, when an object is saved with simple persistence, two references to the
same memory location will cause two copies of the contents of that memory location to be saved.
Not only does this use extra space in the stream, but it also causes the restored object to point to
two distinct copies of the referenced object.

Two Examples of Simple Persistence

Let's look at a two examples of simple persistence. The first example illustrates successful
persistence of fundamental datatypes, and demonstrates the Tools.h++ overloaded operators
operator<< and operator>>, which save and restore persistent objects. The second example
illustrates one of the problems with simple persistence_its inability to maintain pointer
relationships among objects.

Example One: Simple Persisting Objects of Fundamental Type

This example uses simple persistence to save two integers to an output stream po, which saves
the integers to the file int.dat. Then the example restores the two integers from the stream pi,
which reads the integers from the file int.dat.

This manual is related to the following products: