Previous: Data Transfer Functions Up: Data Transfer Functions Next: Building Transfer Functions

Introduction

In Chapter we learned that when a function with arguments is invoked through a global pointer, those arguments are copied to the remote processor object and the function invoked with those copies. Function return values are similarly transferred back to the processor object that invoked the remote function.

While transferring the arguments is simple if they are basic types, it is more complex when they are user-defined structures, particularly if they contain local pointers. (Recall that local pointers are only valid in the processor object in which they are created.)

To give you control over how types are transferred, in CC++ every type has a pair of functions which define how to transfer that type to another processor object. These functions are the data transfer functions for that type.

Once defined for a type, these functions are automatically invoked by the compiler to perform all transfers of that type. You do not need to call these functions explicitly; they are invoked implicitly by calling a function through a global pointer that takes an argument of that type. They are also automatically invoked when a remote function returns a value of that type.

The function


CCVoid& operator<<(CCVoid&,const TYPE& obj_in);

defines how TYPE should be packaged up. It is called by the compiler whenever an object of TYPE needs to be transferred to another processor object.

Similarly, the function


CCVoid& operator>>(CCVoid&,TYPE& obj_out);

defines how TYPE should be unpackaged. It is called by the compiler whenever an object of TYPE is received from another processor object. Upon termination, obj_out will be a copy of the obj_in used as the argument to the operator<< in the initial processor object.

The type CCVoid is a compiler-defined type analogous to class ios of the iostream library. Data transfer functions are used much like the input and output streams of C++. In C++ the functions


ostream& operator<<(ostream&,const TYPE& obj_in);
istream& operator>>(istream&,TYPE& obj_out);

define how TYPE should be packaged to and retrieved from storage.

paolo@cs.caltech.edu