c# - Does the boxed value type have the same address as the actual value type in the object? -


from msdn unbox does

  1. an object reference pushed onto stack.
  2. the object reference popped stack , unboxed value type pointer.
  3. the value type pointer pushed onto stack.

isn't object reference identical value type pointer in case? (both values address value type in heap, since value type member in object)?

for example, 1 element array: address of array same address of first element of array.

void main() {     int[] test = new []{1};     unsafe     {         fixed (int* x = test)         {             fixed (int* y = &test[0])             {                 console.writeline((int)x);                 console.writeline((int)y); // equal             }         }     } } 

why need unbox value type pointer?

edit 280z28: unbox instruction results in pointer data allow (potential) runtime performance advantage based on following:

ecma 335 partition iii §4.32 (excerpt):

unlike box, required make copy of value type use in object, unbox not required copy value type object. typically computes address of value type present inside of boxed object.

the unbox.any instruction added cil when generic types added. unlike unbox, instruction places value on stack instead of pointer value.

end 280z28

isn't object reference identical value type pointer in case?

no. object reference refers object. value type pointer points value.

imagine have piece of paper number 12 on it. put piece of paper in box, , put box in warehouse. position of piece of paper related location of box, not identical location of box. managed reference location of box. value type pointer location of piece of paper. warehouse managed heap.

maybe help. think of boxed int int[] 1 element. location of the array different location of first element of array, right? unboxing dereferencing array.

are both values address value type in heap?

no. 1 value reference object. other managed pointer value type.

does line or line b create new copy (abstractly in il, not machine code wise) of m?

i cannot life of me understand you're trying ask in question.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -