Memory<T> Memory<T> Memory<T> Memory<T> Struct

定义

表示连续内存区域。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

中项的类型Memory<T>The type of items in the Memory<T>.

继承
实现

注解

Span<T>类似Memory<T> ,表示内存的连续区域。Like Span<T>, Memory<T> represents a contiguous region of memory. 但与不同Span<T>的是,不是ref结构。Memory<T> 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.

  • 它可以跨awaityield边界使用。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>(T[]) Memory<T>(T[]) 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>(T[], Int32, Int32) Memory<T>(T[], Int32, Int32) 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 Empty Empty Empty

返回空的 Memory<T> 对象。Returns an empty Memory<T> object.

IsEmpty IsEmpty IsEmpty IsEmpty

指示当前实例是否为空。Indicates whether the current instance is empty.

Length Length Length Length

获取当前实例中的项数。Gets the number of items in the current instance.

Span Span Span Span

返回当前实例的范围。Returns a span from the current instance.

方法

CopyTo(Memory<T>) CopyTo(Memory<T>) CopyTo(Memory<T>) CopyTo(Memory<T>)

Memory<T> 对象的内容复制到目标 Memory<T> 对象。Copies the contents of a Memory<T> object into a destination Memory<T> object.

Equals(Memory<T>) Equals(Memory<T>) Equals(Memory<T>) Equals(Memory<T>)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

Pin() Pin() Pin() Pin()

Memory<T> 对象创建句柄。Creates a handle for the Memory<T> object.

Slice(Int32) Slice(Int32) Slice(Int32) Slice(Int32)

从指定索引处开始的当前内存外形成切片。Forms a slice out of the current memory that begins at a specified index.

Slice(Int32, Int32) Slice(Int32, Int32) Slice(Int32, Int32) Slice(Int32, Int32)

从指定长度的指定索引处开始,在当前内存外形成切片。Forms a slice out of the current memory starting at a specified index for a specified length.

ToArray() ToArray() ToArray() ToArray()

将此内存的内容复制到新数组中。Copies the contents from the memory into a new array.

ToString() ToString() ToString() ToString()

返回此 Memory<T> 对象的字符串表示形式。Returns the string representation of this Memory<T> object.

TryCopyTo(Memory<T>) TryCopyTo(Memory<T>) TryCopyTo(Memory<T>) TryCopyTo(Memory<T>)

将此内存的内容复制到目标 Memory<T> 实例。Copies the contents of the memory into a destination Memory<T> instance.

操作员

Implicit(T[] to Memory<T>) Implicit(T[] to Memory<T>) Implicit(T[] to Memory<T>) Implicit(T[] to Memory<T>)

定义从数组到 Memory<T> 对象的隐式转换。Defines an implicit conversion of an array to a Memory<T> object.

Implicit(ArraySegment<T> to Memory<T>) Implicit(ArraySegment<T> to Memory<T>) Implicit(ArraySegment<T> to Memory<T>) 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>) Implicit(Memory<T> to ReadOnlyMemory<T>) Implicit(Memory<T> to ReadOnlyMemory<T>) Implicit(Memory<T> to ReadOnlyMemory<T>)

定义从 Memory<T> 对象到 ReadOnlyMemory<T> 对象的隐式转换。Defines an implicit conversion of a Memory<T> object to a ReadOnlyMemory<T> object.

扩展方法

Trim<T>(Memory<T>, T) Trim<T>(Memory<T>, T) Trim<T>(Memory<T>, T) 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>) Trim<T>(Memory<T>, ReadOnlySpan<T>) Trim<T>(Memory<T>, ReadOnlySpan<T>) 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) TrimEnd<T>(Memory<T>, T) TrimEnd<T>(Memory<T>, T) TrimEnd<T>(Memory<T>, T)

删除字符内存区域中的指定元素的所有尾随出现次数。Removes all trailing occurrences of a specified element from a character memory region.

TrimEnd<T>(Memory<T>, ReadOnlySpan<T>) TrimEnd<T>(Memory<T>, ReadOnlySpan<T>) TrimEnd<T>(Memory<T>, ReadOnlySpan<T>) 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) TrimStart<T>(Memory<T>, T) TrimStart<T>(Memory<T>, T) TrimStart<T>(Memory<T>, T)

删除内存区域中的指定元素的所有前导出现次数。Removes all leading occurrences of a specified element from a memory region.

TrimStart<T>(Memory<T>, ReadOnlySpan<T>) TrimStart<T>(Memory<T>, ReadOnlySpan<T>) TrimStart<T>(Memory<T>, ReadOnlySpan<T>) 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.

适用于