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 viastackallocor a rawvoid*). TheSpan<T>type is not heapable, meaning that it cannot appear as a field in classes, and it cannot be used acrossyieldorawaitboundaries. -
Memoryis a wrapper around an object that can generate aSpan. For instance,Memoryinstances can be backed byT[],System.String(readonly), and evenSafeHandleinstances.Memorycannot be backed by "transient" unmanaged me