Base of Difference | Span<T> | Array |
Stack | This is possible in Span<T>. | ArraySegment<T> is limited to managed array and we cannot use it to wrap data allocated on the stack by using stackalloc. |
Value Added | Span<T> will not replace anything it is only a value added and this will provides a type safe view into continuous segments of memory | N.A |
Represent Data | Span<T> and array comes from the fact that Span<T> is a view on some data and most of the time this data is represented through an array. | Array is still needed and Span<T> is a just a convenient view on it. |
Read Only | Span<T> provide a read only view. | ArraySegment<T> will not provide a read only view. |
Memory | Span<T> can handle both managed and unmanaged memory. | ArraySegment<T> is only limited to managed memory. |
Relation with GC | This has a special relation with GC which makes it more performant that ArraySegment<T> in stack only scenarios. | Not doing this |