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 中的项的类型。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> 可放置在托管堆上,而 @no__t 不能。This means that Memory<T> can be placed on the managed heap, whereas Span<T> cannot. 因此,Memory<T> 结构与 @no__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.

  • 它可跨 @no__t 0 和 @no__t 边界使用。It can be used across await and yield boundaries.

除了 Memory<T> 外,还可以使用 @no__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.

适用于