Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在 C# 中获取实例(或我不介意的类)的大小?
例如,我知道在 Delphi 中,每个对象都有一个指向类的虚拟方法表的指针,它实现的每个接口的指针,当然还有类的字段。
根据这个基本对象大小在 x86 中是 12 字节,但是,是否有任何“规则”来正确调整它的大小?
这取决于您要做什么。如果您有兴趣了解类型/对象的大小以便与本机代码互操作,您可以使用 Marshal.SizeOf()。除此之外,没有确定的方法来测量物体的大小。