If I have an object:
public class Element {
public int id; // 4 byte
public Element(int id) {
this.id = id;
}
}
// This would be a total of 12 bytes from my understanding (8 for header, 4 for int id)
// and then have another class
public class Unit {
public int uid; // 4 byte
public Element element; // ?? byte
}
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