SafeBuffer.AcquirePointer(Byte*) 方法

定義

重要

此 API 不符合 CLS 規範。

SafeBuffer 物件取得記憶體區塊的指標。

public:
 void AcquirePointer(System::Byte* % pointer);
[System.CLSCompliant(false)]
public void AcquirePointer (ref byte* pointer);
[<System.CLSCompliant(false)>]
member this.AcquirePointer : Byte* -> unit

參數

pointer
Byte*

位元組指標 (以傳址方式傳遞),用來從 SafeBuffer 物件中接收指標。 您必須先將這個指標設定為 null,再呼叫這個方法。

屬性

例外狀況

尚未呼叫 Initialize 方法。

備註

傳回時 AcquirePointer ,您應該藉由確認 pointer 參數為 null來執行界限檢查。 如果不是 null,您必須在條件約束的執行區域中呼叫 SafeBuffer.ReleasePointer 方法, (CER) 。

AcquirePointerSafeHandle.DangerousAddRef會呼叫 方法並公開指標。

下列範例示範如何使用 AcquirePointer 方法:

byte* pointer = null;  
RuntimeHelpers.PrepareConstrainedRegions();  
try {  
    MySafeBuffer.AcquirePointer(ref pointer);  
    // Use pointer here, with your own bounds checking.  
    }  
finally {  
    if (pointer != null)  
        MySafeBuffer.ReleasePointer();  
    }  

如果您將 pointer (轉換為位元組指標) 做為不同類型指標的 (T*) ,則可能會有指針對齊問題。

您必須負責使用此指標檢查的所有界限。

適用於