Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Type Object in Heap

I know that when objects are created in Heap, they also have extra two more fields:

  1. Sync Block Index
  2. Type Object Pointer

So I wonder when Type Object is created in Heap memory and what kind of data it holds? It only represents the metadata of the Type?

I haven't been able to find much detail about that.

like image 420
Tarik Avatar asked Apr 17 '12 01:04

Tarik


1 Answers

The Type object also contains the bytes that back any static fields on the type as well as a method table with one entry per method defined within the type.

Each entry in the method table points to JIT-compiled native code if the method has been executed at least once.

The type object is created the first time the type is instantiated or the first time a static type member is referenced.

I highly recommend buying a copy of Jeffrey Richter's book, CLR via C# if you want to get a really deep understanding of what the CLR does. The section titled "How Things Relate at Runtime" in chapter 4 covers the .NET type allocation process on the heap in detail.

The May 2005 edition of MSDN magazine has an article titled "JIT and Run: Drill Into .NET Framework Internals to See How the CLR Creates Runtime Objects" with some good information as well, specifically the sections on Type Fundamentals and MethodTable.

like image 88
Dan Rigby Avatar answered Oct 22 '22 12:10

Dan Rigby