Answer the question
In order to leave comments, you need to log in
Where is the static class in memory?
In what memory is a static class, on the heap, in theory? A static class is a type object that contains a table of methods, but only static and static constructor?
Answer the question
In order to leave comments, you need to log in
, but method tables are created for each class object individually.
In what memory is a static class, on the heap, in theory?of course, only not in the one that is SOH / LOH, but in the one that Richter mentions as "in fact, there are more than 2 heaps, but you don't need the rest." And to be more precise - in high frequency heap. I don't know why you need this knowledge, but now live with it.
Статический класс - это объект-тип, который содержит таблицу методов, но только статических и статического конструктора?
I remembered that I read about this in the book "Optimization of Applications on the .Net Platform".
Method table
The method table pointer field refers to an internal CLR structure called method table, which in turn refers to another internal structure called EEClass (where EE is short for Execution Engine). Together, the method table and EEClass contain the information needed to select a virtual method, an interface method, a static variable, determine the type of an object at run time, access base class methods, and many other purposes. The method table contains frequently used information required to perform operations by mechanisms such as the virtual method selection mechanism, while the EEClass structure contains information that is used less frequently, such as by the reflection mechanism. You can get acquainted with the contents of both data structures using the commands !DumpMT and !
An array of references to static fields is fixed so that its address cannot be changed by the garbage collector, in addition, static fields of simple types are placed inside the method table, which is not affected by the garbage collector. This ensures that hardwired addresses can be safely used to access such fields.
class MyClass
{
private string _field1 = "Some string 1";
public string Field2 { get; set; }
}
0:003> !do 0000005400006600
Name: ConsoleApplication1.MyClass
MethodTable: 00007ffa2b5c4378
EEClass: 00007ffa2b6d2548
Size: 32(0x20) bytes
File: E:\...\ConsoleApplication1.exe
Fields:
MT Field Offset Type VT Attr Value Name
00007ffa89d60e08 4000002 8 System.String 0 instance 0000005400006620 _field1
00007ffa89d60e08 4000003 10 System.String 0 instance 00000054000035a0 <Field2>k__BackingField
What "Method Table" are you talking about?
If you are talking about VMT, then from the name virtual method table it should be clear that this is only for virtual methods, which are not in C# static classes.
So from a static class, except for its metadata, you do not need to store anything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question