大网数据广告活动
网络与域名解析

The midl_user_allocate Function

· 52CE 我爱测

The midl_user_allocate function is a procedure that must be supplied by developers of RPC applications.

The midl_user_allocate function is a procedure that must be supplied by developers of RPC applications. It allocates memory for the RPC stubs and library routines. Your midl_user_allocate function must match the following prototype:

void __RPC_FAR * __RPC_USER midl_user_allocate (size_t cBytes);

The cBytes parameter specifies the number of bytes to allocate. Both client applications and server applications must implement the midl_user_allocate function unless you are compiling in OSF-compatibility (/osf) mode. Applications and generated stubs call midl_user_allocate directly or indirectly to manage allocated objects. For example:

  • The client and server applications call midl_user_allocate to allocate memory for the application, such as when creating a new node in a tree or linked list.
  • The server stub calls midl_user_allocate when unmarshaling data into the server address space.
  • The client stub calls midl_user_allocate when unmarshaling data from the server that is referenced by an [out] pointer. Note that for [in], [out], and [unique] pointers, the client stub calls midl_user_allocate only if the [unique] pointer value was null on input and changes to a non-null value during the call. If the [unique] pointer was non-null on input, the client stub writes the associated data into existing memory.

If midl_user_allocate fails to allocate memory, it should return a null pointer.

The midl_user_allocate function should return an 8-byte aligned pointer.

For example, the sample programs provided with the Platform Software Development Kit (SDK) implement midl_user_allocate in terms of the C function malloc:

void __RPC_FAR * __RPC_USER midl_user_allocate(size_t cBytes)
{
    return((void __RPC_FAR *) malloc(cBytes));
}

Note:
If the RpcSs package is enabled (for example, as the result of using the [ enable_allocate] attribute), use RpcSmAllocate to allocate memory on the server side. For additional information on [enable_allocate], see MIDL Reference.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。