Using Pointers and ref Structs for Low-Level C# Optimization
summary
Covers low-level C# performance techniques using the ref modifier, managed pointers, and ref structs such as Span<T>. Explains how managed-pointer arithmetic is implemented in C#, its capabilities and pitfalls, why Span<T> was introduced, and examines runtime source code to show how dotnet/runtime authors use ref for library-level optimizations. Also describes using Span<T> to speed up text and binary processing and new ref-struct features added in .NET 9.0.
AI-written summary · about
chapters (15)
- 0:00Introduction
- 1:25Ref modifier history
- 3:11Managed pointers basics
- 7:02Returning refs from functions
- 11:37Unsafe class risks
- 22:27Ref structs intro
- 24:56Span benefits
- 31:02Writable spans
- 34:35SpanStringBuilder optimization
- 38:54Binary data with spans
- 42:23C# 13 ref struct improvements
- 48:30Memory<T> use cases
- 51:45Modifying literal strings
- 54:19Summary and best practices
- 55:42Q&A
