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

Application-Allocated Buffer

· 52CE 我爱测

The ACF attribute \ byte_count\ directs the stubs to use a preallocated buffer that is not allocated or freed by the client support routines.

The ACF attribute [byte_count] directs the stubs to use a preallocated buffer that is not allocated or freed by the client support routines. The [byte_count] attribute is applied to a pointer or array parameter that points to the buffer. It requires a parameter that specifies the buffer size in bytes.

The client-allocated memory area can contain complex data structures with multiple pointers. Because the memory area is contiguous, the application does not have to make several calls to free each pointer and structure individually. As when using the [allocate(all_nodes)] attribute, the memory area can be allocated or freed with one call to the memory-allocation routine or the free routine. However, unlike using the [allocate(all_nodes)] attribute, the buffer parameter is not managed by the client stub but by the client application.

The buffer must be an [out]-only parameter and the buffer length in bytes must be an [in]-only parameter. The [byte_count] attribute can only be applied to pointer types. The [byte_count] ACF attribute is a Microsoft extension to DCE IDL and, as such, is not available if you compile using the MIDL /osf switch.

In the following example, the parameter pRoot uses byte count:

/* function prototype in IDL file (fragment) */
void SortNames(
    [in] short cNames,
    [in, size_is(cNames)] STRINGTYPE pszArray[],
    [in] short cBytes,
    [out, ref] P_TREE_TYPE pRoot  /* tree with sorted data */
);

The [byte_count] attribute appears in the ACF as:

/* ACF file (fragment) */
SortNames([byte_count(cBytes)] pRoot);

The client stub generated from these IDL and ACF files does not allocate or free the memory for this buffer. The server stub allocates and frees the buffer in a single call using the provided size parameter. If the data is too large for the specified buffer size, an exception is raised.

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)

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

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