Span, Memory, and Ref Structs
Span, Memory, and ref structs represent a fundamental shift in how modern C# developers approach performance. While traditional arrays and lists allocate on the managed heap, these constructs enable you to work with contiguous memory—on the stack, in unmanaged buffers, or from existing arrays—without triggering garbage collection. This series takes you from first principles through production patterns.
Over eight years (2018–2026), Span has evolved from a curiosity into the backbone of high-throughput systems. Microsoft's own runtime, the ASP.NET Core framework, and every high-performance library now rely on these primitives. By mastering them, you'll unlock the ability to build parsers, serializers, and network handlers that process terabytes of data with near-zero overhead.
This series is designed for intermediate C# developers ready to level up. You'll need solid knowledge of arrays, generics, and method signatures, but we'll teach everything about memory layout, stack safety, and the subtle rules that govern ref types. Each article is standalone but builds on the previous; read them in order for a cohesive mental model.
Articles in this series
- What Is Span T in C#: A Beginner's Guide
- ReadOnlySpan vs Span in C#: Key Differences
- How to Use Span T for Zero-Allocation Processing
- Memory T in C# Explained: Managed Heap Allocation
- Ref Structs in C#: Safety, Stack, and Constraints
- Stackalloc in C#: Allocating on the Stack Safely
- ArrayPool in C# for High-Performance Applications
- Building an Allocation-Free Parser with Span and Memory
- Pinning Memory in C#: Unmanaged Interop and Span
- Profiling and Benchmarking Span-Based Code with BenchmarkDotNet