PreviousNext

Advanced Memory Management Support

Memory management may also involve setting and swapping the mechanisms used for allocating and freeing memory. The default memory management routines are malloc( ) and free( ), except when the remote call occurs within manager code, in which case the default memory management routines are rpc_ss_allocate( ) and rpc_ss_free( ).

Setting the Client Memory Mechanism
Use the rpc_ss_set_client_alloc_free( ) routine to establish the routines used in allocating and freeing memory.

The syntax of the routine is as follows:

void rpc_ss_set_client_alloc_free (
idl_void_p_t (*p_allocate) (
idl_size_t size),
void (*p_free) (
idl_void_p_t ptr)

);

The p_allocate parameter points to a routine that has the same procedure declaration as the malloc( ) routine, and was used by the client stub when performing memory allocation. The p_free parameter points to a routine that has the same procedure declaration as the free( ) routine, and was used by the client stub to free memory.

Swapping Client Memory Mechanisms
This routine exchanges the current client allocation and freeing mechanism for one supplied in the call. The primary purpose of this routine is to simplify the writing of modular routine libraries in which RPC calls are made. To preserve modularity, any dynamically allocated memory returned by a modular routine library must be allocated with a specific memory allocator. When dynamically allocated memory is returned by an RPC call that is then returned to the user of the routine library, use rpc_ss_swap_client_alloc_free( ) to make sure the desired memory allocator is used. Prior to returning, the modular routine library calls rpc_ss_set_client_alloc_free( ) to restore the previous memory management mechanism.

The syntax of the routine is as follows:

void rpc_ss_swap_client_alloc_free (
idl_void_p_t (*p_allocate) (
idl_size_t size),
void (*p_free) (
idl_void_p_t ptr),
idl_void_p_t (**p_p_old_allocate) (
idl_size_t size),
void (**p_p_old_free) (
idl_void_p_t ptr)
);

The p_allocate parameter points to a routine that has the same procedure declaration as the malloc( ) routine, and was used by the client stub when performing memory allocation. The p_free parameter points to a routine that has the same procedure declaration as the free( ) routine, and was used by the client stub to free memory. The p_p_old_allocate parameter points to a pointer to a routine that has the same procedure declaration as the malloc( ) routine, and was used for memory allocation in the client stub. The p_p_old_free parameter points to a pointer to a routine that has the same procedure declaration as the free( ) routine, and was used for memory release in the client.