什么是.NET对象的内存开销 [英] What is the memory overhead of a .NET Object

查看:176
本文介绍了什么是.NET对象的内存开销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是.NET对象的内存开销?我说的是一个任意裸机对象....内部.NET运作或引用的开销:

What is the memory overhead of an Object in .NET? I'm talking about an arbitrary bare-bones object.... the overhead of the internal .NET workings or references:

var obj = new System.Object();

多少空间OBJ占据堆?

How much space does obj occupy in the heap?

推荐答案

我说起这在博客中的。它的具体实现的,但对于Microsoft .NET CLR v4的,在x86 CLR具有8个字节的每个对象的开销,和x64的CLR具有16字节的每个对象的开销。

I talk about this in a blog post "Of memory and strings". It's implementation-specific, but for the Microsoft .NET CLR v4, the x86 CLR has a per-object overhead of 8 bytes, and the x64 CLR has a per-object overhead of 16 bytes.

然而,也有最小的时间分别是12和24字节大小 - 这只是你得到第4个或8个字节的自由,当你开始储存有用的信息:)

However, there are minimum sizes of 12 and 24 bytes respectively - it's just that you get the first 4 or 8 bytes "free" when you start storing useful information :)

(见博客文章以了解更多信息。)

(See the blog post for more information.)

这篇关于什么是.NET对象的内存开销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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