OSF DCE Application Development Guide--Core Components
OSF DCE Application Development Guide—Core Components
/* Get RPC memory allocation thread handle */
rpc_ss_thread_handle_t thread_handle;
idl_void_p_t (*p_saved_alloc)(unsigned long);
void (*p_saved_free)(idl_void_p_t);
TRY
thread_handle = rpc_ss_get_thread_handle();
CATCH(pthread_badparam_e)
thread_handle = NULL;
ENDTRY
if (thread_handle == NULL) {
/* Set up rpc_ss_allocate environment */
rpc_ss_enable_allocate();
}
rpc_ss_swap_client_alloc_free(
appl_client_alloc,appl_client_free,
&p_saved_alloc,&p_saved_free);
After control returns from the client stub, the client code should again check to see
whether rpc_ss_allocate/free has already been enabled before it calls
rpc_ss_disable_allocate( ):
rpc_ss_set_client_alloc_free(p_saved_alloc,p_saved_free);
/* If we set up rpc_ss_allocate environment, disable it now */
if (thread_handle == NULL)
rpc_ss_disable_allocate();
16.1.3 UsingYour 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
16 − 4 Tandem Computers Incorporated 124245