It’s actually not that difficult:
Currently (float) field-access is rewritten to:
// in:
public class Vec3
{
public float x, y, z;
}
// out:
public class Vec3
{
public long address;
}
// access of field:
Unsafe.getFloat(this.address + field.offset)
When supporting ‘streams’, it would be:
// in:
public class Vec3
{
public float x, y, z;
}
// out:
public class Vec3
{
public long xAddress, yAddress, zAddress;
}
// access of field:
Unsafe.getFloat(this.*Address)
Obviously this can’t work (fast) in a MappedObjectArray, because I would have to move N pointers when calling .index(i) on a mapped type with N fields.
It works just fine with MappedObject though, but memory overhead becomes considerable, as the instances containing the offsets would easily become bigger than the data it refers to.