Memory Usage Question: Vector3f vs. float
during the development of a raycaster we stumbled over a memory usage issue we were unable to explain. In short, we compared the memory usage of a (large) Vector3f[SIZE] array (javax.vecmath.Vector3f) vs. a simple float[SIZE*3]. All tests were done with a 64 bit JRE on a 64 bit fedora 8 with 8 GB ram.
A float in java should have 4 byte (correct me if I am wrong here!), a Vector3f should take 12 byte. Since the Vector3f stores the references to the Vector3f objects, we exected its size to be (SIZE * (12 + reference pointer bytes)). On a 64 bit machine, I'd expect the reference pointer to have 4 byte (correct me again if I am wrong here) , so the total cost for each Vector3f entry should be 20 byte vs. 12 byte of 3 floats in the float array. Since we were running into serious memory problems on the 8 GB machine, I wrote a small test program, allocating some arrays to find out more. The results were:
Vector3f Array: 163 / 358MB
Float Array: 48 / 119MB
Now ... where does the overhead come from? Am I overlooking something? Since we did not know if Vector3f stores some unknown overhead, we also tried it with a MyPoint class, containing only 3 floats. The results were similiar to Vector3f:
MyPoint Array: 162 / 356MB
PS: The original issue is already solved, the ray caster runs fine with a float. However, we are still curious what causes the unexpectedly huge difference.