Writing Allocation Free Code in C#
summary
Argues that cutting allocations improves throughput more than microfast algorithms and shows exactly how using C# 7.0/7.2 features and libraries avoids heap churn: demos use ref return and ref locals to mutate array elements in place, ref readonly and readonly structs to avoid defensive copies, and Span<T> / System.Memory plus ValueTask to process slices allocation free. Uses Rider/Resharper Heap Allocation Viewer and unit tests that assert allocation‑free execution and run green, and notes Span has portable and fast runtime implementations.
AI-written summary · about
chapters (19)
- 0:00Introduction
- 1:22Why
- 1:52Throughput
- 5:13Reducing allocations
- 8:11Reference types vs value types
- 11:43Closures
- 14:38Solutions
- 17:32Reference Semantics
- 19:53Passing by Reference Value Types
- 21:20RefReturn
- 23:57RefLocal
- 28:52RefReadOnly
- 33:42InRef
- 36:42ReadOnly struct
- 39:17Ref Strutt
- 40:27Span of T
- 42:14How does it work
- 43:10Portable version
- 44:20Span
related talks
01h 00mWriting Allocation Free Code in C#
01h 03mTurbocharged: Writing High-Performance C# and .NET Code
39mMemory Efficient Java
01h 00mMoving Faster: Everyday efficiency in modern C++
42mMeasure Twice, Optimize Once: Real-World .NET Profiling with Visual Studio
49mMaking Allocators Work, Part I
58mLocal (Arena) Memory Allocators Part 1
27m“From security to performance to GPU programming..."
