Investigation of CLR via SOS

喜夏-厌秋 提交于 2019-12-01 11:15:42
Hans Passant

!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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!