Editéieren

Deelen iwwer


Memory-related and span types

.NET includes a number of interrelated types that represent a contiguous, strongly typed region of arbitrary memory. These types 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, AsSpan(), a collection expression, 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. In high-performance code, spans are often used to avoid allocating strings unnecessarily.

The types include:

For more information, see the System.Buffers namespace.

Working with memory and span

Because the memory-related and span-related types are typically used to store data in a processing pipeline, it's important that you 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