beautypg.com

HP Integrity NonStop J-Series User Manual

Page 210

background image

The problem is that on some compilers godzilla and godzilla.mothra_ have the same address!
Upon restoration of godzilla, godzilla.mothra_ is streamed out as a value, and godzilla is
streamed out as a reference to godzilla.mothra_. If godzilla and godzilla.mothra have the same
address, the restore of godzilla fails because the extraction operator attempts to initialize godzilla
with the contents of godzilla.mothra_.

There are two ways to overcome this difficulty. The first is to structure your class so that simple
data members, such as int, precede data members that are isomorphically persistent. Using this
method, class Godzilla looks like this:

struct Godzilla {
int wins_;
Mothra mothra_; // mothra_ now has a different address.
};

If Godzilla is structured as shown here, mothra_ is displaced from the front of godzilla and can't
be confused with godzilla. The variable wins_, of type int, is saved with simple persistence and
is not stored in the isomorphic save table.

The second approach to solving the problem of identical addresses between a class and its
members is to insert an isomorphically persistable member as a pointer rather than a value. For
Godzilla this would look like:

struct Godzilla {
Mothra* mothraPtr_;// mothraPtr_ points to a different address.
int wins_;
};

In this second approach, mothraPtr_ points to a different address than godzilla, so confusion is
once again avoided.

Don't Use Sorted RWCollections to Store Heterogeneous
RWCollectables

When you have more than one different type of

RWCollectable

stored in an

RWCollection

, you

can't use a sorted RWCollection. For example, this means that if you plan to store

RWCollectableString

s and

RWCollectableDate

s in the same RWCollection, you can't store them

in a sorted RWCollection such as RWBtree. The sorted RWCollections are

RWBinaryTree

,

RWBtree,

RWBTreeDictionary,

and

RWSortedVector

.

The reason for this restriction is that the comparison functions for sorted

RWCollection

s expect

that the objects to be compared will have the same type.

This manual is related to the following products: