SafeBuffer SafeBuffer SafeBuffer SafeBuffer Class

定义

警告

此 API 现已过时。

提供可用于读取和写入的受控内存缓冲区。Provides a controlled memory buffer that can be used for reading and writing. 尝试访问受控缓冲区(不足和溢出)以外的内存会引发异常。Attempts to access memory outside the controlled buffer (underruns and overruns) raise exceptions.

public ref class SafeBuffer abstract : Microsoft::Win32::SafeHandles::SafeHandleZeroOrMinusOneIsInvalid
[System.Security.SecurityCritical]
[System.Obsolete("SafeBuffer may be unavailable in future releases.")]
public abstract class SafeBuffer : Microsoft.Win32.SafeHandles.SafeHandleZeroOrMinusOneIsInvalid
type SafeBuffer = class
    inherit SafeHandleZeroOrMinusOneIsInvalid
    interface IDisposable
Public MustInherit Class SafeBuffer
Inherits SafeHandleZeroOrMinusOneIsInvalid
继承
派生
属性
实现

注解

必须调用SafeBuffer.Initialize方法之前使用的任何实例SafeBufferYou must call the SafeBuffer.Initialize method before you use any instance of SafeBuffer. 若要存储的实例时避免争用SafeBuffer对象在静态变量中,应使用以下方法之一:To avoid races when you store an instance of a SafeBuffer object in a static variable, you should use one of the following approaches:

备注

隐式锁定静态类构造函数中的分配。Assignments in a static class constructor are implicitly locked.

构造函数

SafeBuffer(Boolean) SafeBuffer(Boolean) SafeBuffer(Boolean) SafeBuffer(Boolean)

创建 SafeBuffer 类的新实例,并指定是否可靠地释放缓冲区句柄。Creates a new instance of the SafeBuffer class, and specifies whether the buffer handle is to be reliably released.

属性

ByteLength ByteLength ByteLength ByteLength

获取缓冲区的大小(以字节为单位)。Gets the size of the buffer, in bytes.

IsClosed IsClosed IsClosed IsClosed

获取一个值,该值指示句柄是否已关闭。Gets a value indicating whether the handle is closed.

(Inherited from SafeHandle)
IsInvalid IsInvalid IsInvalid IsInvalid

方法

AcquirePointer(Byte*) AcquirePointer(Byte*) AcquirePointer(Byte*) AcquirePointer(Byte*)

从内存块的 SafeBuffer 对象中获取一个指针。Obtains a pointer from a SafeBuffer object for a block of memory.

Close() Close() Close() Close()

标记句柄,以便释放资源。Marks the handle for releasing and freeing resources.

(Inherited from SafeHandle)
DangerousAddRef(Boolean) DangerousAddRef(Boolean) DangerousAddRef(Boolean) DangerousAddRef(Boolean)

手动递增 SafeHandle 实例中的引用计数器。Manually increments the reference counter on SafeHandle instances.

(Inherited from SafeHandle)
DangerousGetHandle() DangerousGetHandle() DangerousGetHandle() DangerousGetHandle()

返回 handle 字段的值。Returns the value of the handle field.

(Inherited from SafeHandle)
DangerousRelease() DangerousRelease() DangerousRelease() DangerousRelease()

手动递减 SafeHandle 实例中的引用计数器。Manually decrements the reference counter on a SafeHandle instance.

(Inherited from SafeHandle)
Dispose() Dispose() Dispose() Dispose()

释放 SafeHandle 类使用的所有资源。Releases all resources used by the SafeHandle class.

(Inherited from SafeHandle)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放 SafeHandle 类所使用的非托管资源,并指定是否执行常规释放 (Dispose) 操作。Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.

(Inherited from SafeHandle)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
Initialize(UInt32, UInt32) Initialize(UInt32, UInt32) Initialize(UInt32, UInt32) Initialize(UInt32, UInt32)

通过使用指定的元素数和元素大小,指定内存缓冲区的分配大小。Specifies the allocation size of the memory buffer by using the specified number of elements and element size. 在使用 SafeBuffer 实例之前,必须调用此方法。You must call this method before you use the SafeBuffer instance.

Initialize(UInt64) Initialize(UInt64) Initialize(UInt64) Initialize(UInt64)

定义内存区域的分配大小(以字节为单位)。Defines the allocation size of the memory region in bytes. 在使用 SafeBuffer 实例之前,必须调用此方法。You must call this method before you use the SafeBuffer instance.

Initialize<T>(UInt32) Initialize<T>(UInt32) Initialize<T>(UInt32) Initialize<T>(UInt32)

通过指定值类型的数目,定义内存区域的分配大小。Defines the allocation size of the memory region by specifying the number of value types. 在使用 SafeBuffer 实例之前,必须调用此方法。You must call this method before you use the SafeBuffer instance.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Read<T>(UInt64) Read<T>(UInt64) Read<T>(UInt64) Read<T>(UInt64)

按指定的偏移量从内存中读取值类型。Reads a value type from memory at the specified offset.

ReadArray<T>(UInt64, T[], Int32, Int32) ReadArray<T>(UInt64, T[], Int32, Int32) ReadArray<T>(UInt64, T[], Int32, Int32) ReadArray<T>(UInt64, T[], Int32, Int32)

从自偏移量开始的内存中读取指定数量的值类型,并将它们写入从索引开始的数组中。Reads the specified number of value types from memory starting at the offset, and writes them into an array starting at the index.

ReleaseHandle() ReleaseHandle() ReleaseHandle() ReleaseHandle()

如果在派生类中重写,执行释放句柄所需的代码。When overridden in a derived class, executes the code required to free the handle.

(Inherited from SafeHandle)
ReleasePointer() ReleasePointer() ReleasePointer() ReleasePointer()

释放由 AcquirePointer(Byte*) 方法获取的指针。Releases a pointer that was obtained by the AcquirePointer(Byte*) method.

SetHandle(IntPtr) SetHandle(IntPtr) SetHandle(IntPtr) SetHandle(IntPtr)

将句柄设置为预先存在的指定句柄。Sets the handle to the specified pre-existing handle.

(Inherited from SafeHandle)
SetHandleAsInvalid() SetHandleAsInvalid() SetHandleAsInvalid() SetHandleAsInvalid()

将句柄标记为不再使用。Marks a handle as no longer used.

(Inherited from SafeHandle)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
Write<T>(UInt64, T) Write<T>(UInt64, T) Write<T>(UInt64, T) Write<T>(UInt64, T)

将值类型写入内存中的给定位置。Writes a value type to memory at the given location.

WriteArray<T>(UInt64, T[], Int32, Int32) WriteArray<T>(UInt64, T[], Int32, Int32) WriteArray<T>(UInt64, T[], Int32, Int32) WriteArray<T>(UInt64, T[], Int32, Int32)

通过读取从输入数组中指定位置开始的字节,将指定数目的值类型写入内存位置。Writes the specified number of value types to a memory location by reading bytes starting from the specified location in the input array.

字段

handle handle handle handle

指定要包装的句柄。Specifies the handle to be wrapped.

(Inherited from SafeHandle)

安全性

SecurityCriticalAttribute
直接调用方需要完全信任。requires full trust for the immediate caller. 不能由部分受信任的或透明的代码使用此成员。This member cannot be used by partially trusted or transparent code.

适用于