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 類別所使用的 Unmanaged 資源,指定是否要執行一般處置 (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 的淺層複本 (Shallow Copy)。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.

適用於