If I have an object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public class Element { public int id; public Element(int id) { this.id = id; } }
public class Unit { public int uid; public Element element; } |
would the the second object's size be: 16 bytes?
8 header, 4 int uid, 4 Element (reference?)
or would it contain the size of the Element object as well thus end up being 24 bytes total?
8 header, 4 int uid, 12 Element
What I'm asking is how many bytes is ?? byte within the Unit object?
I'll end up using a lot of objects so I need to figure out the best way to store an object.
Would it be better to store variable element within Unit as an int elementId field or use Element element? With int I'd be doing a search to grab the element but I will be storing all of these into a HashMap so it wouldn't be a linear search.
How it'll work is both are stored in 2 separate HashMap, but when I need to read the Element of Unit, I can use just unit.element to return Element or do elementHashMap.get(unit.elementId) depending on how I structure the data