整数与整数:关于记忆 [英] Integer vs int: with regard to memory

查看:149
本文介绍了整数与整数:关于记忆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道
整数n 占用的内存是否存在差异,而 int n

I was wondering if there is a difference in the memory occupied by Integer n, and int n.

我知道 int n 正常占用4个字节,如何整数n

I know int n occupies 4 bytes normally, how about Integer n

推荐答案

通常,Hotspot中Java对象使用的堆内存包括:

In general, the heap memory used by a Java object in Hotspot consists of:


  • 一个对象标题,由几个字节的管家信息组成;

  • 内存为原始字段,根据它们的大小(int n-> 32位)

  • 引用字段的内存(每个4字节)(整数n) - > 32位)

  • 填充:在对象数据之后可能会有一些浪费未使用的字节,使每个对象从一个方便的字节数的地址开始并减少数量表示指向对象的指针所需的位数。

  • an object header, consisting of a few bytes of "housekeeping" information;
  • memory for primitive fields, according to their size (int n->32 bits)
  • memory for reference fields (4 bytes each) (Integer n ->32 bits)
  • padding: potentially a few "wasted" unused bytes after the object data, to make every object start at an address that is a convenient multiple of bytes and reduce the number of bits required to represent a pointer to an object.

根据Mark Peters的建议我想添加以下链接
http://www.javamex.com/tutorials/memory/object_memory_usage.shtml

as per the suggestion of Mark Peters I would like add the link below http://www.javamex.com/tutorials/memory/object_memory_usage.shtml

这篇关于整数与整数:关于记忆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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