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

属性

例外

注解

返回时 AcquirePointer ,应通过验证 pointer 参数是否为 null来执行边界检查。 如果不是 null,则必须在受约束的执行区域中调用 SafeBuffer.ReleasePointer 方法, (CER) 。

AcquirePointerSafeHandle.DangerousAddRef调用 方法并公开指针。 Read与 方法不同,它不会更改指针的当前位置。

以下示例演示如何使用 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*) 不同类型的指针 (,则可能存在指针对齐问题。

你必须负责使用此指针检查的所有边界。

适用于