next up previous contents
Next: pointer array Up: Type declarations in the Previous: struct

Array

In making an RPC, the function arguments are sent to the server, which resides in different address space, usually on a remote host. We want to minimize the data transfered to reduce the overhead. When the data to be sent is an array, we should only send those needed elements. In powerRPC, when an argument is declared as char msg[1024] with a constant 1024 as the array length, exactly 1024 characters will be sent to/from the server. To tell powerRPC to be more efficient, we can define the size attribute for a fixed array, as shown below,

    struct msg_t 
    {
       int len;
       char msg[size=len, 1024];
    };
where we specify that the number of needed elements in array msg is len.

Or even this,

    struct msg_t2 
    {
       char msg[size = strlen(msg)+1, 1024];
    };
The size attribute is used only during the code generation of the XDR routines, the generated header file contains the C declaration with the size = expression part stripped out.

One important restriction on the expression used for the size attribute: one can not use global variables. This is because the XDR routines are used by both the server and client symmetrically, a variable in one address space is different from one in another address space.

PowerRPC does not recognize declaration of extern variables or functions, and it does not check the type of the expression used for the size attribute.



Copyright (C) Netbula LLC, 1996