Leggere in inglese Modifica

Condividi tramite


Memory<T> Struct

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Represents a contiguous region of memory.

C#
public readonly struct Memory<T> : IEquatable<Memory<T>>
C#
public readonly struct Memory<T>

Type Parameters

T

The type of items in the Memory<T>.

Inheritance
Memory<T>
Implements

Remarks

Like Span<T>, Memory<T> represents a contiguous region of memory. Unlike Span<T>, however, Memory<T> is not a ref struct. This means that Memory<T> can be placed on the managed heap, whereas Span<T> cannot. 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.

  • It can be used across await and yield boundaries.

In addition to Memory<T>, you can use System.ReadOnlyMemory<T> to represent immutable or read-only memory.

Constructors

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

Creates a new Memory<T> object that includes a specified number of elements of an array beginning at a specified index.

Memory<T>(T[])

Creates a new Memory<T> object over the entirety of a specified array.

Properties

Empty

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.

Methods

CopyTo(Memory<T>)

Copies the contents of a Memory<T> object into a destination Memory<T> object.

Equals(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()

Creates a handle for the Memory<T> object.

Slice(Int32, Int32)

Forms a slice out of the current memory starting at a specified index for a specified length.

Slice(Int32)

Forms a slice out of the current memory that begins at a specified index.

ToArray()

Copies the contents from the memory into a new array.

ToString()

Returns the string representation of this Memory<T> object.

TryCopyTo(Memory<T>)

Copies the contents of the memory into a destination Memory<T> instance.

Operators

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

Defines an implicit conversion of an ArraySegment<T> object to a Memory<T> object.

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

Defines an implicit conversion of a Memory<T> object to a ReadOnlyMemory<T> object.

Implicit(T[] to Memory<T>)

Defines an implicit conversion of an array to a Memory<T> object.

Extension Methods

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.

Applies to

Prodotto Versioni
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.0 (package-provided), 2.1

See also