Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your reasoning seems to go like this:</p> <ul> <li>System.Int32 is derived from System.Object</li> <li>a derived type is always laid out in memory in the same way as its base type</li> <li>therefore, System.Int32 is laid out in memory the same as System.Object</li> </ul> <p>Yes?</p> <p>The second premise is false. Derivation and memory layout have pretty much nothing to do with each other. Do you believe this premise to be true? If so, what led you to believe it?</p> <p>UPDATE: I think it would be helpful to describe how a method call on a value type works.</p> <p>Suppose you've got a value type:</p> <pre><code>struct S { public int x; public override string ToString() { return "Hello!" + x; } } ... S s = new S(); s.x = 0x00112233; s.ToString(); </code></pre> <p>What code do we generate? The code does this:</p> <ul> <li>reserve four bytes on the stack for s.x.</li> <li>write the bytes 00 11 22 33 into that memory.</li> <li>call the method S.ToString, passing a reference to the memory location we just allocated on the stack.</li> </ul> <p>Why do we need to store anything other than the four bytes of s.x on the stack? We have everything we need already in hand to do the call: a reference to the variable containing the instance of S, and the exact name and location of the exact method implementation that we're calling. There is no need to store anything having to do with System.Object anywhere. There is no "part of it used by object class"; we have no need of such a thing, so there isn't any such thing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload