RpcSs Memory Management Package

The default allocator/deallocator pair used by the stubs and run time when allocating memory on behalf of the application is midl_user_allocate/midl_user_free. However, you can choose the RpcSs package instead of the default by using the ACF attribute [enable_allocate]. The RpcSs package consists of RPC functions that begin with the prefix RpcSs or RpcSm. The RpcSs package is not recommended for Windows applications.

Note  The Rpcss Memory Management Package is obsolete. It is recommended that midl_user_allocate and midl_user_free are used in its place.
 

In /osf mode, the RpcSs package is enabled for MIDL-generated stubs automatically when full pointers are used, when the arguments require memory allocation, or as a result of using the [enable_allocate] attribute. In the default (Microsoft extended) mode, the RpcSs package is enabled only when the [enable_allocate] attribute is used. The [enable_allocate] attribute enables the RpcSs environment by the server-side stubs. The client side becomes alerted to the possibility that the RpcSs package may be enabled. In /osf mode, the client side is not affected.

When the RpcSs package is enabled, allocation of memory on the server side is accomplished with the private RpcSs memory management allocator and deallocator pair. You can allocate memory using the same mechanism by calling RpcSmAllocate (or RpcSsAllocate). Upon return from the server stub, all the memory allocated by the RpcSs package is automatically freed. The following example shows how to enable the RpcSs package:

/* ACF file fragment */

[ 
    implicit_handle(handle_t GlobalHandle),
    enable_allocate
]
interface iface
{
}

/*Server management routine fragment. Replaces p=midl_user_allocate(size); */

    p=RpcSsAllocate(size);                /*raises exception */
    p=RpcSmAllocate(size, &status);       /*returns error code */

Your application can explicitly free memory by invoking the RpcSsFree or RpcSmFree function. Note that these functions do not actually free memory. They mark it for deletion. The RPC library releases the memory when your program calls RpcSsDisableAllocate or RpcSsDisableAllocate.

You can also enable the memory management environment for your application by calling the RpcSmEnableAllocate routine (and you can disable it by calling the RpcSmDisableAllocate routine). Once enabled, application code can allocate and deallocate memory by calling functions from the RpcSs package.

 

 

Show: