RpcSmAllocate

The RpcSmAllocate function allocates memory within the RPC stub memory management function and returns a pointer to the allocated memory or NULL.

#include <rpc.h>
void * RPC_ENTRY RpcSmAllocate( 
  size_t Size,         
  RPC_STATUS* pStatus  
);
 

Parameters

Size
Specifies the size of memory to allocate (in bytes).
pStatus
Specifies a pointer to the returned status.

Remarks

The RpcSmAllocate routine allows an application to allocate memory within the RPC stub memory management environment. Prior to calling RpcSmAllocate, the memory management environment must already be established. For memory management called within the stub, the server stub itself may establish the necessary environment. See RpcSmEnableAllocate for more information. When using RpcSmAllocate to allocate memory not called from the stub, the application must call RpcSmEnableAllocate to establish the required memory management environment.

The RpcSmAllocate routine returns a pointer to the allocated memory if the call is successful. Otherwise, a NULL is returned.

When the stub establishes the memory management, it frees any memory allocated by RpcSmAllocate. The application can free such memory before returning to the calling stub by calling RpcSmFree.

By contrast, when the application establishes the memory management, it must free any memory allocated. It does so by calling either RpcSmFree or RpcSmDisableAllocate.

To manage the same memory within the stub memory management environment, multiple threads can call RpcSmAllocate and RpcSmFree. In this case, the threads must share the same stub memory management thread handle. Applications pass thread handles from thread to thread by calling RpcSmGetThreadHandle and RpcSmSetThreadHandle.

See Memory Management for a complete discussion of the various memory management conditions supported by RPC.

Return Values

Value Meaning
RPC_S_OK Success
RPC_S_OUT_OF_MEMORY Out of Memory

QuickInfo

  Windows NT: Yes
  Windows CE: Unsupported.
  Header: Declared in rpcndr.h.
  Import Library: Link with rpcrt4.lib.

See Also

RpcSmEnableAllocate, RpcSmDisableAllocate, RpcSmFree, RpcSmGetThreadHandle, RpcSmSetThreadHandle