Previous: Building Transfer Functions Up: Data Transfer Functions Next: Automatic Transfer Function Generation
For structures with local pointers, then, the information needs to be packaged in such a way as to enable the reconstruction of the same structure in the other processor object. For instance:
class Vector { int length; double* elements; friend CCVoid& operator<<(CCVoid&,const Vector&); friend CCVoid& operator>>(CCVoid&,Vector&); };CCVoid& operator<<(CCVoid& v,const Vector& input) { v << input.length; for (int i=0; i<input.length; i++) v << input.elements[i]; return v; }
CCVoid& operator>>(CCVoid& v,Vector& output) { v >> output.length; output.elements = new double[output.length]; for (int i=0; i<output.length; i++) v >> output.elements[i]; return v; }
The local pointer is never really transferred. Rather, the elements of the array that it references are sent in an agreed upon order -- from lowest index to highest index -- so that the identical array can be reconstructed remotely. Also notice that no constructor has been defined for type Vector, and thus CC++ will define one automatically.
The problems with transferring local pointers are also present for arrays, and must be dealt with similarly.