How large, in bytes, is a boxed primitive like java.lang.Integer
or java.lang.Character
in Java?
An int
is 4 bytes, a typical pointer is also 4 byte (if not compressed by the JVM). Is the cost for an Integer (without caching) thus 4 bytes + 4 bytes = 8 bytes
? Are there any more hidden fields within the box-object or additional overhead incurred regarding objects (i.e. is there a general cost for objects that I'm not aware of?).
I'm not interested in caching issues. I know that Integers within a certain range are cached by the JVM.
One could rephrase the question: What is the maximum factor to be multiplied on the amount of memory used for boxed values versus primitive values?
EDIT: I do understand that multiple implementations of the JVM exist. What is the typical cost in a typical 32-bit HotSpot Implementation?