I.e. what is the name of the Value Type data structure stored on the stack, that references an object on the heap?
I.e. an object reference is System.What(if anything)?
I know it’s not a pointer, or is it?
I know it’s “like” a pointer.
I know it is “owned by the garbage collector”.
I SUPERSTITIOUSLY believe that when you instantiate an object (i.e. a reference type), that the IL gives the instruction to the CLR to allocate the “stack reference/heap value pair” in memory (e.g.
...
.locals init ([0] int32 i1,
[1] object o1,
[2] int64 l1)
IL_0000: nop
IL_0001: ldc.i4.4
IL_0002: stloc.0
IL_0003: newobj instance void [mscorlib]System.Object::.ctor()
IL_0008: stloc.1
IL_0009: ldloc.0
IL_000a: box [mscorlib]System.Int32
...
)
, and that the actual reference is inaccessible at the language or IL level (except for copying/assigning to a new reference or manipulating the referenced object), and that the object reference’s allocation is created and managed by the CLR/CLI and the CLR injects an OBJECTREF DWORD value into the stack (or similar).
Please set me straight and put an end to this for all book authors and Google searches.
Thanks!
It’s a pointer, sized to the native word length (ie, 32-bit pointer on x86, 64-bit pointer on x64). It doesn’t have a CTS-exposed ‘type’ in the sense that I think you mean.