PreviousNext

Using Your Own Allocation and Free Routines

At times it might be necessary for client code to change the routines that the client stubs use to allocate and free memory. For example, client code that is making an RPC call might want to direct the RPC client stubs to use special "debug'' versions of malloc( ) and free( ) that check for memory leaks. Another example might be an application that uses DCE RPC but needs to preserve its users' ability to free memory returned from the application by using the platform's memory management scheme (rather than exposing the user to DCE).

Client code that wants to use its own memory allocation and free routines can use the rpc_ss_swap_client_alloc_free( ) routine to exchange the current client allocation and freeing mechanism for one supplied in the call. The routine returns pointers to the memory allocation and free routines formerly in use. Before calling rpc_ss_swap_client_alloc_free( ), client code must ensure that it has not been called from a manager routine.

Deallocation of allocated storage returned from the client stubs is not automatic. Therefore, client code must ensure that it uses the free routine that it specified in the call to rpc_ss_swap_client_alloc_free( ) to deallocate each piece of allocated storage.

Client code that swaps in memory management routines with rpc_ss_swap_client_alloc_free( ) should use the rpc_ss_set_client_alloc_free( ) routine before it exits to restore the old allocation and free routines.