a**d 发帖数: 85 | 1 int[] array = new int[20]; 4 bytes per element, total 80 bytes.
HashMap map = new HashMap<>(20).
4 bytes for key+4 bytes for value, so total 160 bytes.
如果假设array,map都存满了,map的key从0-19
这样考虑对吗?就是说map总比array要多space因为它的key还要占空间。
如果是这样,那么我用一个HashSet去存这20个int的话空间就和array一样了?
谢谢 |
s**x 发帖数: 7506 | 2 Hash table is trading space for performance.
A big array plus chained list for a typical implementation.
Usually the array can dynamically grow. It uses about 80 bytes even it is
empty, one of my team member tested this using old stl. |
a**d 发帖数: 85 | 3 嗯,hashtable要是填不满会浪费空间。
就是想知道算memory usage时候它的key也应该考虑在内吧? |
w****r 发帖数: 15252 | 4 现在不是有新的玩意叫做cocurrentHashMap |