OSF DCE Application Development Guide--Introduction and Style Guide
RPC Parameters
The client code to excercise the sparse array transmitted type is as follows:
sparse_array_t test_array;
/* Create a sparse array with only three nonzero members */
memset(test_array,0,sizeof(unsigned32)*S_ARRAY_SIZE);
test_array[0] = 2;
test_array[20] = 4;
test_array[31] = 8;
/*
* When compressed, this array requires 7 32-bit integers, as opposed
* 32 32-bit integers for the uncompressed array. If you don’t care
* about reconstructing the sparse array on the server side, you can
* get even more efficiency.
*/
ship_array(binding_h, &test_array, &status);
The server manager code is as follows:
void ship_array(
handle_t binding_h,
sparse_array_t *array,
error_status_t *status
)
{
int i;
/*
* Print the elements of the sparse array.
*/
for (i = 0; i < S_ARRAY_SIZE; i++)
{
printf("%i0, (*array)[i]);
}
*status = error_status_ok;
}
Note that the free_inst routine will not be needed if the transmitted type does not contain
pointers. However, the routine is called by the stub automatically in any case, so at least
a null routine must be provided. As an exercise, you might add printf()s to each
callback to see when it is called. You could also add code to show the format of the
transmitted array before it is reconstructed by the from_xmit routine. Finally, you can
create an even more efficient compression by not attempting to reconstruct the original
array on the server side.
124246 Tandem Computers Incorporated 6− 29