Integer vs int: with regard to memory(Integer vs int:关于内存)
问题描述
我想知道是否有不同的内存占用整数 n
和 int n
.
I was wondering if there is a difference in the memory occupied by
Integer n
, and int n
.
我知道int n
正常占用4个字节,Integer 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 位)
- reference 字段的内存(每个 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
这篇关于Integer vs int:关于内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Integer vs int:关于内存


- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01