I work with Java 1.3, so it does not support generics. I came up with a shadow job. I want to know if Integer and Double objects have unnecessary overhead; I guess I ask: do whole units make as much space as int? The same question for Double and double.
From what I know, an array of objects contains an array of 32-bit integers that actually store the address in the object in memory, regardless of the array. But when I explicitly create an array of primitives like I am here, the result will be bad. Since AFAIK, an array of primitives is actually an array of data, not pointers to data. Or am I relying too much on C ++?
So, if the Array in the DataPackage really contains pointers instead of primitives, I have to go. But if they themselves hold the primitives, access to the data will be a problem, since double is 64 bits of data, but the pointer to it is still 32 bits.
public class DataPackage { private String dataType; private Object data; public DataPackage(String type, int numOfItems) { dataType = type; if (type.equals("Wheels")) { data = new int[numOfItems * 2]; } if (type.equals("Arms")) { data = new int[numOfItems * 1]; } if (type.equals("Joysticks")) { data = new double[numOfItems * 2]; } if (type.equals("Buttons")) { data = new boolean[numOfItems * 4]; } } public void update(Object t1) { data = t1; } public Object getData() { return data; } public String toString() { return "This contains " + dataType; } }
To access this data, I allocated an array of objects as an array of integers, then call the intValue () function: temp is an array of ints. I should also indicate that getData in the input simply returns a DataPackage.
temp[0] = ((Integer[])input.getData("Wheels").getData())[0].intValue();
I can’t just run this code right now because it is for FRC Robot at my school and at school.
java object double pointers integer
Davidthefat Dec 28 '11 at 9:16 a.m. 2011-12-28 21:16
source share