next up previous contents index
Next: g_xdr_superclass Up: XDR Methods Previous: XDR Methods

g_xdr_instance

The most important function used in this example is the function for writing and reading instances:

bool_t g_xdr_instance(XDR *xdrp, INSTANCE **inst)
which takes an pointer to an instance pointer as second parameter. It is responsible for handling (compare this with the g_xdr_array function in the previous section)

References are handled in the same way as for arrays: the first time g_xdr_instance is called on an instance it is written/read, all subsequent calls on this instance just create/resolve references. When a reference is resolved while reading, the refcount of the instance is corrected (which is not possible for arrays).

Memory management is only necessary in two cases when the function is called for reading: if the given instance is NULL (again the pointer, not the pointer pointer!) or has the wrong class a new instance is created, in the second case the given instance is deleted.

Skipping unknown data can be very useful. If you create for example a subclass of Adapt2d with its own "xdr" method for your numerics and write an instance of this class to a file, somebody else who hasn't got this subclass and its "xdr" method will still be able to read the file -- in this case an Adapt2d instance will be created and the subclass data is ignored -- and to visualize the data.

Additionally g_xdr_instance writes/reads some class information before calling the appropriate "xdr" method. Therefore: NEVER write an instance directly using the "xdr" method, but ALWAYS use g_xdr_instance instead.


SFB 256 Universität Bonn and IAM Universität Freiburg

Copyright © by the Sonderforschungsbereich 256 at the Institut für Angewandte Mathematik, Universität Bonn.