Memory- and span-related types

Starting with .NET Core 2.1, .NET includes a number of interrelated types that represent a contiguous, strongly typed region of arbitrary memory. These include:

System.Span<T>, System.Memory<T>, and their readonly counterparts are designed to allow the creation of algorithms that avoid copying memory or allocating on the managed heap more than necessary. Creating them (either via Slice or their constructors) does not involve duplicating the underlying buffers: only the relevant references and offsets, which represent the "view" of the wrapped memory, are updated.


For earlier frameworks, Span<T> and Memory<T> are available in the System.Memory NuGet package.

For more information, see the System.Buffers namespace.

Working with memory and span

Because the memory- and span-related types are typically used to store data in a processing pipeline, it is important that developers follow a set of best practices when using Span<T>, Memory<T>, and related types. These best practices are documented in Memory<T> and Span<T> usage guidelines.

See also