NET Core and More

TH20 Manual Memory Management in .NET Framework

08/15/2019

3:30pm - 4:45pm

Level: Advanced

Adam Furmanek

Software Developer

Amazon

Value types are on a stack and reference types are on a heap - this is a typical answer when one is asked about placement of values in memory. However, is it really defined that way in the .NET Framework specification? Or can we bend the rules and manage memory differently?

During the session I will show how to allocate memory directly by hand using TypedReferences. We will see that it is possible to allocate reference type on a stack, how to implement generic List faster than the default implementation provided by .NET Framework, how to implement custom memory allocator (with any fragmentation strategy we like), and finally, how to hack new keyword provided by the platform to use different allocator. We will examine memory dumps with WinDBG, emit IL code dynamically, and generate machine code for x86 directly in runtime.

You will learn:

  • Understanding memory structure of allocated objects in .NET
  • Understanding machine code behind .NET Framework allocations
  • Implementing custom memory allocator and verifying its performance