共用方式為


force_allocate屬性

ACF 屬性 [force_allocate] 會強制使用 midl_user_allocate 來配置指標參數,而不是將配置優化。

[ [function-attribute-list <>] ] type-specifier <> [pointer- <>declarator <>] function-name <>( [ force_allocate [ , parameter-attribute-list <> ] ] type-specifier <> [declarator <>] , ...);

參數

這個屬性沒有參數。

備註

RPC 嘗試藉由提供內部記憶體緩衝區的指標,將伺服器上的記憶體配置降到最低。 這種方法可能會導致嘗試直接在 RPC 提供的指標上呼叫 midl_user_free 的應用程式發生問題,因為無法釋放已優化的指標。 使用 [force_allocate] 標記參數將會防止針對衍生它的所有指標進行這項優化。

[force_allocate]的另一個常見用法是,如果應用程式需要大於所指向記憶體的對齊方式,則保證所指向記憶體的對齊方式。 例如,應用程式通常會在位元組的泛型陣列中傳遞資料,而不是使用實際類型,但位元組只會保證在 1 對齊,這可能會導致假設較大的對齊方式的應用程式發生問題。 藉由使用 [force_allocate]標記參數,應用程式可以保證指向的所有記憶體都會與 midl_user_allocate保證的對齊方式相等。

範例

/* IDL file */
void Func1([in, out, string] char **ppstr);
void Func2([in] long s, [in, size_is(s)] byte *pData);

/* ACF file */

/* e.g. The application wishes to call midl_user_free on *ppstr and supply a new pointer */
Func1([force_allocate] pstr);

/* e.g. pData really points to a structure that needs an alignment greater than 1 */
Func2([force_allocate] pData);

另請參閱

避免隱藏資訊

設計 64 位相容介面

midl_user_allocate

midl_user_free

分配