On Hashtables and Java Storage Efficiency
I did some more work tonight on hash tables and Java storage efficiency.
Turns out that an int actually does store entries in 4 bytes.
I created an int array with 2M ints. This does in fact use 4 bytes per entry.
Which is basically what you’d expect.
Creating an array of 2M Integer objects uses 20 bytes per object.
So 1/2 the problem with java.util.TreeMap is that it uses auto-boxing which means each int is wrapped in an Integer so a value that would normally only take 4 bytes now takes 20. Ouch.
That’s a 5x waste of space right there.
This guy uses only 27 bytes per entry. This is MUCH better than the original 100 bytes per entry I was seeing with java.util.HashMap.
However, this is still a far cry from the ideal 12 bytes per entry that I could accomplish via the FastMap idea I had earlier.