I am new to programming and this is creating a lot of confusion for me.
Suppose we have the following statement:
Int32 i = 1;
i
's content is stored on memory, which will be four bytes : 00000000 00000000 00000000 00000001
How does CLR access this memory location later? Does CLR store the address to this memory block somewhere?
System.Int32
is a value type, no references used.
In fact, a local variable may never be in memory at all, if the compiler can find a CPU register to hold it during its entire life.
If it is in memory, its address will be found by adding an offset to the stack pointer (ESP
) or to the address of the reference-typed (class
in C#) object that contains it.
In the code generated from the JIT, variables of value types are indistinguishable from variables used by native code (there's no object header or anything like that).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With