Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A object or array reference occupies one 32 bit word (4 bytes) on a 32 bit JVM or Davlik VM. A <code>null</code> takes the same space as a reference. (It has to, because a null has to fit in a reference-typed slot; i.e. instance field, local variable, etc.)</p> <p>On the other hand, an object occupies a minimum of 2 32 bit words (8 bytes), and an array occupies a minimum of 3 32 bit words (12 bytes). The actual size depends on the number and kinds of fields for an object, and on the number and kind of elements for an array.</p> <hr> <p>For a 64 bit JVM, the size of a reference is 64 bits, unless you have configured the JVM to use compressed pointers:</p> <blockquote> <p>-XX:+UseCompressedOops Enables the use of compressed pointers (object references represented as 32 bit offsets instead of 64-bit pointers) for optimized 64-bit performance with Java heap sizes less than 32gb.</p> </blockquote> <hr> <p>This is the nub of your question, I think.</p> <blockquote> <p>Before determining the size of the hash table, I wanted to know how much memory would it consume in order not to exagerate.</p> </blockquote> <p>If you allocate a <code>HashMap</code> or <code>Hashtable</code> with a large initial size, the majority of the space will be occupied by the hash array. This is an array of references, so the size will be <code>3 + initialSize</code> 32 bit words. It is unlikely that this will be significant ... unless you get your size estimate drastically wrong.</p> <p>However, I think you are probably worrying unnecessarily about performance. If you are storing objects in a default allocated <code>HashMap</code> or <code>Hashtable</code>, the class will automatically resize the hash table as it gets larger. So, provided that your objects have a decent hash function (not too slow, not hashing everything to a small number of values) the hash table should not be a direct CPU performance concern.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload