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

Definition

Represents a contiguous region of memory.

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

Type Parameters

T

The type of items in the Memory<T>.

Inheritance

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[]) Memory<T>(T[]) Memory<T>(T[]) Memory<T>(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)

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

Properties

Empty Empty Empty Empty

Returns an empty Memory<T> object.

IsEmpty IsEmpty IsEmpty IsEmpty

Indicates whether the current instance is empty.

Item[Range] Item[Range] Item[Range] Item[Range]
Length Length Length Length

Gets the number of items in the current instance.

Span Span Span Span

Returns a span from the current instance.

Methods

CopyTo(Memory<T>) CopyTo(Memory<T>) CopyTo(Memory<T>) CopyTo(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>)

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

Creates a handle for the Memory<T> object.

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

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

Slice(Range) Slice(Range) Slice(Range) Slice(Range)
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()

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

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

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

Operators

Implicit(T[] to Memory<T>) Implicit(T[] to Memory<T>) Implicit(T[] to Memory<T>) Implicit(T[] to 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>)

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

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

Applies to