Home > OS >  How to view the memory size and layout of a specific managed C# reference type?
How to view the memory size and layout of a specific managed C# reference type?

Time:02-10

I would like some tool or method of viewing the size and layout in memory of a specific C# managed reference type, including all of its instance fields. Obviously this is an implementation detail and my program itself doesn't need to know it, but I, the human programmer, would like to understand how the CLR organizes the actual memory layouts of certain of my C# classes for the purposes of optimization and curiosity. (I've read articles and understand the high-level theory about the memory layout of C# objects, but I would like to see the how the CLR actually does it in-practice.)

If it matters, I'm using .NET 6.

CodePudding user response:

There's the SOS Debugging Extension which has a DumpClass command. This dumps out information about the EEClass structure for a type, which includes e.g. what offset each field is located at.

  • Related