Language

ReadOnlyMemory Struct

Definition

Represents a contiguous region of memory, similar to ReadOnlySpan. Unlike ReadOnlySpan, it is not a byref-like type.

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

Type Parameters

T

The object type from which the contiguous region of memory will be read.

Inheritance
ReadOnlyMemory
Implements

Constructors

Name Description
ReadOnlyMemory(T[], Int32, Int32)

Creates a new memory region over the portion of the target array beginning at a specified position and including a specified number of elements.

ReadOnlyMemory(T[])

Creates a new memory region over the entirety of the target array.

Properties

Name Description
Empty

Gets an empty ReadOnlyMemory.

IsEmpty

Gets a value that indicates whether this read-only memory region is empty.

Length

Gets the number of items in the memory region.

Span

Gets a span from the memory region.

Methods

Name Description
CopyTo(Memory)

Copies the contents of the read-only memory region into a destination memory region.

Equals(Object)

Determines whether the specified object is equal to the current read-only memory region.

Equals(ReadOnlyMemory)

Determines whether the current instance and a specified ReadOnlyMemory objects are equal.

GetHashCode()

Returns the hash code for this ReadOnlyMemory.

Pin()

Creates a handle for the memory.

Slice(Int32, Int32)

Forms a slice out of the given memory region starting at start position for length elements.

Slice(Int32)

Forms a slice out of the given memory region, beginning at a specified position and continuing to its end.

ToArray()

Copies the contents from the memory region into a new array.

ToString()

Returns the string representation of this read-only memory instance.

TryCopyTo(Memory)

Tries to copy the contents of the readonly-only memory into the destination and returns a value that indicates whether the copy operation succeeded.

Operators

Name Description
Implicit(ArraySegment to ReadOnlyMemory)

Defines an implicit conversion of a ArraySegment to a ReadOnlyMemory.

Implicit(T[] to ReadOnlyMemory)

Defines an implicit conversion of an array to a ReadOnlyMemory.

Extension Methods

Name Description
Trim(ReadOnlyMemory, ReadOnlySpan)

Removes all leading and trailing occurrences of a set of elements specified in a read-only span from a read-only memory region.

Trim(ReadOnlyMemory, T)

Removes all leading and trailing occurrences of a specified element from a read-only memory region.

TrimEnd(ReadOnlyMemory, ReadOnlySpan)

Removes all trailing occurrences of a set of elements specified in a read-only span from a read-only memory region.

TrimEnd(ReadOnlyMemory, T)

Removes all trailing occurrences of a specified element from a read-only memory region.

TrimStart(ReadOnlyMemory, ReadOnlySpan)

Removes all leading occurrences of a set of elements specified in a read-only span from a memory region.

TrimStart(ReadOnlyMemory, T)

Removes all leading occurrences of a specified element from a memory region.

Applies to

See also