大小()等效引用类型? [英] sizeof() equivalent for reference types?

查看:198
本文介绍了大小()等效引用类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一种方式来获得一个引用类型的实例的大小。 sizeof的仅仅是值类型。这可能吗?

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?

推荐答案

如果你不介意它是一个小完美的不准确,并为比较的目的,你可以序列化对象/ s和衡量(以字节为单位例如)

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)

编辑(我一直在发布后的思考)的:因为​​它是一个多一点的sizeof值类型的更复杂,例如:引用类型可以有对其他对象等等......有没有一个准确,简单的方法来做到这一点,我知道了......

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

这篇关于大小()等效引用类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆