This document describes the relationship between Memory<T>
and its related classes (MemoryPool<T>
, IMemoryOwner<T>
, etc.). It also describes best practices when accepting Memory<T>
instances in public API surface. Following these guidelines will help developers write clear, bug-free code.
-
Span<T>
is the basic exchange type that represents contiguous buffers. These buffers may be backed by managed memory (such asT[]
orSystem.String
). They may also be backed by unmanaged memory (such as viastackalloc
or a rawvoid*
). TheSpan<T>
type is not heapable, meaning that it cannot appear as a field in classes, and it cannot be used acrossyield
orawait
boundaries. -
Memory
is a wrapper around an object that can generate aSpan
. For instance,Memory
instances can be backed byT[]
,System.String
(readonly), and evenSafeHandle
instances.Memory
cannot be backed by "transient" unmanaged me