sizeof() equivalent for reference types?

前端 未结 6 1296
醉酒成梦
醉酒成梦 2020-11-30 12:20

I\'m looking for a way to get the size of an instance of a reference type. sizeof is only for value types. Is this possible?

6条回答
  •  旧巷少年郎
    2020-11-30 12:47

    If you don't mind it being a little less accurate than perfect, and for comparative purposes, you could serialize the object/s and measure that (in bytes for example)

    EDIT (I kept thinking after posting): Because it's a little more complicated than sizeof for valuetypes, for example: reference types can have references to other objects and so on... there's not an exact and easy way to do it that I know of...

提交回复
热议问题