Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Data Structure Memory Estimates

Does anyone have a list of rough rule-of-thumb estimators for the various data structures? e.g.

  • Arrays
  • Lists
  • HashMaps
  • LinkedLists

I remember seeing some of these estimates thrown around in various places, but I can't seem to find one right now.

I know it's actually incredibly complicated, especially for things like HashMaps, but I'm looking for something really rough, like:

Memory(HashMap) = fixedOverhead + variableOverhead * tableSize + A*numKeys + B*numValues + Memory(allKeys) + Memory(allValues)

of course it'll vary a lot depending on this and that, but even a rough within-a-factor-of-2 estimate would be immensely useful.

like image 842
Li Haoyi Avatar asked Mar 22 '12 01:03

Li Haoyi


2 Answers

Check this out. From Java code to Java heap-Understanding and optimizing your application's memory usage

like image 173
George Avatar answered Sep 24 '22 21:09

George


This table is quite exhaustive, and deals precisely with the JDK implementation choices measured in bytes per entry/element. If you want to do it on your own machine -- if you're running on a different machine, perhaps -- this Google Code site will let you download its source. http://code.google.com/p/memory-measurer/wiki/ElementCostInDataStructures

like image 45
Louis Wasserman Avatar answered Sep 21 '22 21:09

Louis Wasserman