本文介紹了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:關于內存的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!