Great Resource ▸ http://benhall.io/a-super-simplified-exp lanation-of-net-garbage-collection/
Slide 22
Stack vs Heap What?
Lifetime
When disposed?
Time to dispose
Stack
Local values Local references (just the ref part)
Stack frame
Deterministic
Constant (near instant)
Heap
Reference object instances
Unrestricted
GC non-deterministic
It depends (non-trivial)
Slide 23
Watch out for hidden allocations ▸ Let’s see some examples
In Parameters - cont. ▸ Essentially readonly ref ▸ Where you want to want to pass by-ref for performance, with the safety and behaviour or by-value ▸ Watch out for copying with invoking methods on non-readonly structs
Slide 32
Ref extension methods
Slide 33
Ref locals ▸ Reference semantics with value types
Slide 34
Ref locals ▸ Can be thought of as aliases
Slide 35
Ref returns
Slide 36
Ref Struct ▸ Aka ref-like ▸ Stack-only! ▸ To support Span<T>
Slide 37
Ref Struct
Slide 38
“
The great Eric Lippert once wrote “The Stack Is An Implementation Detail”, and basically that’s not true anymore. - Jon Skeet
Slide 39
Span<T> ▸ Abstraction over arbitrary memory Span<T>
Marshal.AllocHGlobal()
stackalloc []
new []
Libraries using Span<T> ( just some) ▸ Utf8Json ▸ SpanJson ▸ ZeroFormatter
▸ StackExchange.Redis
Slide 61
Case study JustEat.StatsD PRs
Low hanging fruit: #55, #59, #63, #65 Master class by dv00d00: #104 - Zero Allocations
Slide 62
Good Reads Adam Sitnik - Span Marc Gravell - Spans and ref Parts 1 & 2 Span<T> spec Vladimir Sadov All About Span: Exploring a New .NET Mainstay Stephen Toub ▸ Maarten Balliauw ▸ ▸ ▸ ▸ ▸
Slide 63
Summary
Slide 64
THANKS! Any questions? You can find me at @stuartblang