beautypg.com

Don't save distinct objects with the same address – HP Integrity NonStop J-Series User Manual

Page 209

background image

Instead, you should write your functions the following way:

// RIGHT!

void rwSaveGuts(RWFile& file, const Elmer& elmer) {
file << elroy_;
file << *elroyPtr_;
}

void rwRestoreGuts(RWFile& file, Elmer& elmer){
file >> elroy_;
file >> elroyPtr_;
}

If you correct rwRestoreGuts and rwSaveGuts as suggested above, then the isomorphic save and
restore tables can use the address of Elmer::elroy_ to update Elmer::elroyPtr_ if necessary.

Summary: Because of the possibility of having both a value and a pointer that points to that
value in the same class, it's a good idea to define your rwSaveGuts and rwRestoreGuts member
functions so that they always operate on values before pointers.

Don't Save Distinct Objects with the Same Address

You must be careful not to isomorphically save distinct objects that may have the same address.
The internal tables that are used in isomorphic and polymorphic persistence use the address of an
object to determine whether or not an object has already been saved.

The following example assumes that all the work has been done to make Godzilla and Mothra
isomorphically persistable:

class Mothra {/* _ */};
RWDEFINE_PERSISTABLE(Mothra)

struct Godzilla {
Mothra mothra_;
int wins_;
};

RWDEFINE_PERSISTABLE(Godzilla)
/*_ */
Godzilla godzilla;
/* _ */
stream << godzilla;
/* _ */
stream >> godzilla; // The restore may be garbled!

When godzilla is saved, the address of godzilla will be saved in an isomorphic save table. The
next item to be saved is godzilla.mothra_. Its address is saved in the same internal save table.

This manual is related to the following products: