Tips and tricks for uka.transport

Since cycle detection for references is time consuming, you may experience performance problems when multidimensional arrays are marshaled. Multidimensional arrays are implemented in Java as arrays of references to other arrays.

Consider the following piece of code that is legal Java:

// Multidimensional array with aliasing
int array = new int[] {1, 2, 3, 4};
int[][] marray = new int[][] {array, array};

The multidimensional array marray consists of two references to the same one-dimensional array array. If marray is marshaled, it is guaranteed that an array with the same structure is read at the other end.

Especially for large arrays you may want to save the overhead for exactly analyzing the alias structure of arrays during marshaling. You can prevent this overhead by replacing the calls to writeObject() in your marshalReferences() method with calls to specialized methods in the class ValueIO:

// Marshaling multidimensional arrays as values
protected void marshalReferences(MarshalStream _stream)
    ValueIO.writeValue(_stream, marray);
Last modified 16 years ago Last modified on Aug 22, 2005 9:14:10 AM