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:关于内存
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
