本文介紹了Integer vs int:關(guān)于內(nèi)存的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想知道是否有不同的內(nèi)存占用整數(shù) n
和 int n
.
I was wondering if there is a difference in the memory occupied by
Integer n
, and int n
.
我知道int n
正常占用4個字節(jié),Integer n
I know int n
occupies 4 bytes normally, how about Integer n
推薦答案
一般來說,Hotspot中Java對象使用的堆內(nèi)存包括:
In general, the heap memory used by a Java object in Hotspot consists of:
- 一個對象頭,由幾個字節(jié)的管家"信息組成;
- 原始字段的內(nèi)存,根據(jù)其大小(int n->32 位)
- reference 字段的內(nèi)存(每個 4 字節(jié))(整數(shù) n ->32 位)
- 填充:在對象數(shù)據(jù)之后可能會浪費"一些未使用的字節(jié),以使每個對象從一個方便的字節(jié)倍數(shù)的地址開始,并減少表示指向?qū)ο蟮闹羔標(biāo)璧奈粩?shù).
- 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.
根據(jù) 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
這篇關(guān)于Integer vs int:關(guān)于內(nèi)存的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!