属性会增加实例的内存大小吗? [英] Does Properties increase memory size of Instances?

查看:55
本文介绍了属性会增加实例的内存大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个愚蠢的问题,但是对象属性是否每个实例占用任何内存?

This is probably a stupid question, but does object Properties occupy any memory per instance?

据我了解,在实例化对象时,每个值字段都占用其大小,并且引用字段类型每个字段4个字节.但是,假设您有一个具有1000个属性的对象,可以通过其他对象来获取数据,这些属性本身是否占用了任何内存?

As I've understand it when you instantiate an object each value field occupies its size and reference field types 4 bytes per field. But say you have an object with 1000 properties that fetches data via some other object, does those properties occupy any memory in themselves?

自动属性自然会起作用,因为它只是语法糖,但似乎不像普通属性应该...

Automatic properties naturally does since it's just syntactic sugar but it doesn't seem like ordinary Properties should...

推荐答案

在这方面,属性就像普通方法一样.

Properties are just like ordinary methods in that respect.

代码需要存储在某个位置(每个类型一次),并且每个实例所使用的任何字段(自动属性!)都必须存储.局部变量也会占用一些内存.

The code needs to be stored somewhere (once per Type) and any fields that are used (Auto properties!) need to be stored per instance. Local variables will also take up some memory.

这篇关于属性会增加实例的内存大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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