PreviousNext

Memory Management for Pointed-to Nodes

A full pointer can change its value across a call. Therefore, stubs must be able to manage memory for the pointed-to nodes. Managing memory involves allocating and freeing memory for user data structures.

Allocating and Freeing Memory

Manager code within RPC servers usually uses the rpc_ss_allocate( ) routine to allocate storage. Storage that is allocated by rpc_ss_allocate( ) is released by the server stub after any output parameters have been marshalled by the stubs. Storage allocated by other allocators is not released automatically but must be freed by the manager code. When the manager code makes a remote call, the default memory management routines are rpc_ss_allocate( ) and rpc_ss_free( ).

The syntax of the rpc_ss_allocate( ) routine is as follows:

idl_void_p_t rpc_ss_allocate (idl_size_t size);

The size parameter specifies the size of the memory allocated.

Note: In ANSI standard C environments, idl_void_p_t is defined as void * and in other environments is defined as char *.

Use rpc_ss_free( ) to release storage allocated by rpc_ss_allocate( ). You can also use the rpc_ss_free( ) routine to release storage pointed to by a full pointer in an input parameter and have the freeing of the memory reflected on return to the calling application by specifying the reflect_deletions attribute as an operation_attribute. See the topic describing how to declare IDL operations for more information.

The syntax of the routine is as follows:

void rpc_ss_free (idl_void_p_t node_to_free);

The node_to_free parameter specifies the location of the memory to be freed.

Enabling and Disabling Memory Allocation
It may be necessary to call manager routines from different environments; for example, when the application is both a client and a server of the same interface. In this case, the same routine may be called both from server manager code and from client code. The rpc_ss_allocate( ) routine, when used by the manager code to allocate memory, must be initialized before its first use. The stub performs the initialization automatically. Code, other than stub code, that calls a routine, which in turn calls rpc_ss_allocate( ), first calls the rpc_ss_enable_allocate( ) routine.

The syntax of the routine is as follows:

void rpc_ss_enable_allocate (void);

The environment set up by the rpc_ss_enable_allocate( ) routine is released by calling the rpc_ss_disable_allocate( ) routine. This routine releases all memory allocated by calls to rpc_ss_allocate( ) since the call to rpc_ss_enable_allocate( ) was made. It also releases memory that was used by the memory management mechanism for internal bookkeeping.

The syntax of the routine is as follows:

void rpc_ss_disable_allocate (void);