Memory<T> 結構

定義

代表連續的記憶體區域。Represents a contiguous region of memory.

generic <typename T>
public value class Memory : IEquatable<Memory<T>>
public struct Memory<T> : IEquatable<Memory<T>>
type Memory<'T> = struct
Public Structure Memory(Of T)
Implements IEquatable(Of Memory(Of T))

類型參數

T

@No__t-0 中的專案類型。The type of items in the Memory<T>.

繼承
Memory<T>
實作

備註

如同 Span<T>Memory<T> 代表連續的記憶體區域。Like Span<T>, Memory<T> represents a contiguous region of memory. 不同于 Span<T>Memory<T> 不是ref 結構Unlike Span<T>, however, Memory<T> is not a ref struct. 這表示 Memory<T> 可以放在受控堆積上,而 Span<T> 則不能。This means that Memory<T> can be placed on the managed heap, whereas Span<T> cannot. 因此,Memory<T> 結構並沒有與 Span<T> 實例相同的限制。As a result, the Memory<T> structure does not have the same restrictions as a Span<T> instance. 特別之處在於:In particular:

  • 它可用來做為類別中的欄位。It can be used as a field in a class.

  • 可以在 await 和 @no__t 1 界限之間使用。It can be used across await and yield boundaries.

除了 Memory<T> 以外,您還可以使用 System.ReadOnlyMemory<T> 來表示不可變或唯讀的記憶體。In addition to Memory<T>, you can use System.ReadOnlyMemory<T> to represent immutable or read-only memory.

建構函式

Memory<T>(T[])

在整個指定的陣列上建立新的 Memory<T> 物件。Creates a new Memory<T> object over the entirety of a specified array.

Memory<T>(T[], Int32, Int32)

建立新的 Memory<T> 物件,其中包含開始於指定索引之陣列的指定項目數。Creates a new Memory<T> object that includes a specified number of elements of an array beginning at a specified index.

屬性

Empty

傳回空的 Memory<T> 物件。Returns an empty Memory<T> object.

IsEmpty

指出目前的執行個體是否為空的。Indicates whether the current instance is empty.

Length

取得目前執行個體中的項目數目。Gets the number of items in the current instance.

Span

傳回目前執行個體的範圍。Returns a span from the current instance.

方法

CopyTo(Memory<T>)

Memory<T> 物件的內容複製到目的地 Memory<T> 物件。Copies the contents of a Memory<T> object into a destination Memory<T> object.

Equals(Memory<T>)

判斷指定的 Memory<T> 物件是否等於目前的物件。Determines whether the specified Memory<T> object is equal to the current object.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

Pin()

建立 Memory<T> 物件的控制代碼。Creates a handle for the Memory<T> object.

Slice(Int32)

從起始於指定索引的目前記憶體形成配量。Forms a slice out of the current memory that begins at a specified index.

Slice(Int32, Int32)

從起始於指定索引之指定長度的目前記憶體形成配量。Forms a slice out of the current memory starting at a specified index for a specified length.

ToArray()

將記憶體的內容複製到新的陣列。Copies the contents from the memory into a new array.

ToString()

傳回此 Memory<T> 物件的字串表示。Returns the string representation of this Memory<T> object.

TryCopyTo(Memory<T>)

將記憶體的內容複製到目的地 Memory<T> 執行個體。Copies the contents of the memory into a destination Memory<T> instance.

運算子

Implicit(ArraySegment<T> to Memory<T>)

定義從 ArraySegment<T> 物件到 Memory<T> 物件的隱含轉換。Defines an implicit conversion of an ArraySegment<T> object to a Memory<T> object.

Implicit(Memory<T> to ReadOnlyMemory<T>)

定義從 Memory<T> 物件到 ReadOnlyMemory<T> 物件的隱含轉換。Defines an implicit conversion of a Memory<T> object to a ReadOnlyMemory<T> object.

Implicit(T[] to Memory<T>)

定義從陣列到 Memory<T> 物件的隱含轉換。Defines an implicit conversion of an array to a Memory<T> object.

擴充方法

Trim<T>(Memory<T>, T)

從記憶體區域中移除所有開頭和尾端指定元素項目。Removes all leading and trailing occurrences of a specified element from a memory region.

Trim<T>(Memory<T>, ReadOnlySpan<T>)

從記憶體區域中移除唯讀範圍中指定的所有開頭和尾端元素集項目。Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a memory region.

TrimEnd<T>(Memory<T>, T)

從字元記憶體區域中移除所有尾端指定元素項目。Removes all trailing occurrences of a specified element from a character memory region.

TrimEnd<T>(Memory<T>, ReadOnlySpan<T>)

從記憶體區域中移除唯讀範圍中指定的所有尾端元素集項目。Removes all trailing occurrences of a set of elements specified in a read-only span from a memory region.

TrimStart<T>(Memory<T>, T)

從記憶體區域中移除所有開頭指定元素項目。Removes all leading occurrences of a specified element from a memory region.

TrimStart<T>(Memory<T>, ReadOnlySpan<T>)

從記憶體區域中移除唯讀範圍中指定的所有開頭元素集項目。Removes all leading occurrences of a set of elements specified in a read-only span from a memory region.

適用於