Skip to main content

Chapter 13: High-performance memory operations

In this chapter

  • 13.1 Evolution of memory management
  • 13.2 Span<T>: unifying memory access
    • Zero-copy slicing
    • Performance benchmark example
    • Searching values (.NET 8+)
  • 13.3 Memory<T> and lifetime management
    • When to use Memory<T>
    • MemoryPool<T>
    • Passing existing memory to Stream APIs (.NET 11)
  • 13.4 ref struct and performance limitations
    • Why are stack-only restrictions necessary?
    • Strict compiler constraints and rule violations
  • 13.5 Array pooling
    • Correct usage pattern: rent and return
  • 13.6 stackalloc and collection expressions
    • Dynamic size stackalloc
  • 13.7 Memory safety evolution: pointer relaxation and unsafe expressions (C# 15)
    • Enabling the updated rules
    • Operations that no longer require unsafe
    • Expression-level unsafe(...)
    • Safety assertions and caller contracts
  • 13.8 Optimizing GC settings
  • Summary
  • Glossary

This chapter is not available in the free preview. Purchase the book to read the complete edition now.

Buy this book