Hash memory

I studied the internal structure of the Hash Map, where I came across the following details:

  • The implementation is an array of HashMap $ input objects:

  • Each HashMap $ record contains: - int KeyHash - The next object - The key of the object - The value of the object

  • The default capacity is 16 entries

  • Empty size is 128 bytes

  • Overhead - 48 bytes for HashMap, plus (16 + (entries * 4 bytes)) for array - plus overhead for HashMap $ Entry objects

  • An additional 32 bytes to enter the entry key. The overhead of the HashMap is therefore: - 48 bytes plus 36 bytes per record

Can someone explain to me "Overhead - 48 bytes for HashMap, plus (16 + (entries * 4 bytes)) for the array" and "Extra 32 bytes for entering the key value * The overhead for HashMap is therefore: - 48 bytes plus 36 bytes per record

I cannot understand how these conclusions came, for example, how we came across this latest information about the memory of a hash map.

+4
source share
1 answer

, SO. , Java (, OOPS, fixnums ..).

OpenJDK 7, HashMap:


- 48 HashMap

. , 8 .

, , keySet(), values() entrySet(). , 12 32- .

// from AbstractMap
transient volatile Set<K>        keySet = null;
transient volatile Collection<V> values = null;

// from HashMap
private transient Set<Map.Entry<K,V>> entrySet = null

int: size, threshold modCount. 12 .

float: loadFactor. 4 .

(Entry[] table). 4 .

( static final , )

, 40- HashMap. 48 , . , - , , . . , . , 40 48 ( ).


16 + ( * 4 )

Entry[] table HashMap, .

8 , 4 bytes length. 12 , 16. , , .

Entry, 4 . .


32 ↔

, 8 .

:

final K key;    // a reference, 4 bytes
V value;        // a reference, 4 bytes
Entry<K,V> next;  // a reference, 4 bytes
final int hash; // an integer primitive, 4 bytes

16 .

24 . , 36.


, . IBM vm? , 64- ? , 16 ( - Java 8?).

, .

+2

All Articles