The Rpcss package is the recommended memory management model and provides the best overall stub performance for memory management. 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.
In /osf mode, the Rpcss package is enabled for MIDL-generated stubs automatically whenever full pointers are used, whenever the arguments require memory allocation, or as a result of using the enable_allocate attribute. In 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
]
{
}
/*Server management routine fragment. Replaces p=midl_user_allocate(size); */
p=RpcSsAllocate(size); /*raises exception */
p=RpcSmAllocate(size, &status); /*returns error code */
You can also enable the memory management environment for your application by calling the RpcSmEnableAllocate routine (and can disable it by calling the RpcSmDisableAllocate routine). Once enabled, application code can allocate and deallocate memory by calling functions from the RpcSs* or RpcSm* package.