Investigation of CLR via SOS

后端 未结 1 1162
失恋的感觉
失恋的感觉 2021-01-15 05:58

Currently I am digging deeper into CLR and try to find proper size of my managed objects.

I have two simple types:

XClass

          


        
相关标签:
1条回答
  • 2021-01-15 06:55

    !dso == Dump Stack Objects. Focus on "Objects", a struct is not an object.

    The only reason that SOS is capable of finding objects references at all is because it can use the metadata that the jitter generates when it compiles a method. This data is used by the garbage collector when it performs stack walks to find object references back. You can read more about it in this answer. Value type values are missing from this metadata, the GC doesn't care about them.

    You can infer the size of a struct by creating an array of them, giving the first field of the struct a distinctive value. Look at the array with the VS debugger, Debug + Windows + Memory + Memory1, put the variable name in the Address field. You'll the struct values back in the hex dump, after the array header. Do beware that structure sizes depend on the CLR version and the bitness of the process so only ever use this info as a hint.

    0 讨论(0)
提交回复
热议问题