Friday, November 25, 2005

Case of the stingy JVM

Did you know this ?
-----------------------------------------------------------------------------------------------------------------
The Java virtual machine specification defines the range of values for each of the data types, but does not define their sizes. The number of bits used to store each data type value is a decision of the designers of individual implementations.
-Bill Venners, Inside the Java Virtual Machine
------------------------------------------------------------------------------------------------------------------
When you create an int you would think that the JVM allocates 32 bits to it. But wait, it is possible that it may allocate fewer bits if the value you assign to the int does not require all the 32 bits. What will happen if you assign it a larger value? I do not know for sure, but I think it will relocate the int to some other location on the heap and give it more memory.
Now is that 'stingy' or 'smart' ?

No comments: