MemoryMarshal
Provides a collection of methods for interoperating with Memory<T>, ReadOnlyMemory<T>,
Span<T>, and ReadOnlySpan<T>.
Casts a Span of one primitive type T to Span of bytes.
That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
Casts a ReadOnlySpan of one primitive type T to ReadOnlySpan of bytes.
That type may not contain pointers or references. This is checked at runtime in order to preserve type safety.
Creates a Memory<T> from a ReadOnlyMemory<T>.
Casts a Span of one primitive type TFrom to another primitive type TTo.
These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
public static ReadOnlySpan<TTo> Cast<TFrom, TTo>(ReadOnlySpan<TFrom> span) where TFrom : struct where TTo : struct
Casts a ReadOnlySpan of one primitive type TFrom to another primitive type TTo.
These types may not contain pointers or references. This is checked at runtime in order to preserve type safety.
Creates a new memory over the portion of the pre-pinned target array beginning
at 'start' index and ending at 'end' index (exclusive).
Returns a reference to the 0th element of the Span. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Returns a reference to the 0th element of the ReadOnlySpan. If the Span is empty, returns a reference to the location where the 0th element
would have been stored. Such a reference can be used for pinning but must never be dereferenced.
Reads a structure of type T out of a read-only span of bytes.
Creates an IEnumerable<T> view of the given memory to allow
the memory to be used in existing APIs that take an IEnumerable<T>.
Get an array segment from the underlying memory.
If unable to get the array segment, return false with a default array segment.
public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, out TManager manager) where TManager : MemoryManager<T>
Gets an MemoryManager<T> from the underlying read-only memory.
If unable to get the TManager type, returns false.
public static bool TryGetMemoryManager<T, TManager>(ReadOnlyMemory<T> memory, out TManager manager, out int start, out int length) where TManager : MemoryManager<T>
Gets an MemoryManager<T> and start, length from the underlying read-only memory.
If unable to get the TManager type, returns false.
public static bool TryGetString(ReadOnlyMemory<char> memory, out string text, out int start, out int length)
Attempts to get the underlying String from a ReadOnlyMemory<T>.
Reads a structure of type T out of a span of bytes.
If the span is too small to contain the type T, return false.
Writes a structure of type T into a span of bytes.
If the span is too small to contain the type T, return false.
Writes a structure of type T into a span of bytes.