Pointers

It is very efficient to use pointers as C function parameters. The pointer costs only a few bytes and can be used to access a large amount of memory. However, in a distributed application, the client and server procedures can reside in different address spaces on different computers that may not have access to the same memory.

When one of the remote procedure's parameters is a pointer to an object, the client must transmit a copy of that object and its pointer to the server. If the remote procedure modifies the object through its pointer, the server returns the pointer and its modified copy.

MIDL offers pointer attributes to minimize the amount of required overhead and the size of your application. For example, you can specify a binary tree using the following definition:

typedef struct _treetype {
    long               lValue;
    struct _treetype * left;
    struct _treetype * right;
} TREETYPE;

TREETYPE * troot;
 

The contents of a tree node can be accessed by more than one pointer, thus making it more complicated for the RPC support code to manage the data and the pointers. The underlying stub code must resolve the various pointers to the addresses and determine whose copy of the data represents the most recent version.

The amount of processing can be reduced if you guarantee that your pointer is the only way the application can access that area of memory. The pointer can still have many of the features of a C pointer. For example, it can change between null and non-null values or stay the same. However, as long as the data referenced by the pointer is unique to the pointer, you can reduce the amount of processing by the stubs. To do this, designate such a pointer by using the unique attribute.

You can further reduce the complexity if you specify that the non-null pointer to an address of valid memory will not change during the remote call. However, the contents of memory can change and the data returned from the server will be written into this area on the client. To do this, designate such a pointer, known as a reference pointer, by using the ref attribute.