4 ms·
Moreover, they can be used in composite objects without pointer chasing. Suppose class A is a 32-byte value type. Then class B { A a1; A a2
by blt 8y ago
Moreover, they can be used in composite objects without pointer chasing. Suppose class A is a 32-byte value type. Then
class B {
A a1;
A a2;
}
is one continuous 64-byte block of memory. Without value types, each A will be allocated separately on the heap, and B will be a pair of pointers.
Lack of value types makes it hard to get cache efficient memory layouts in Java.
- trhway 8y agoOf course if/when a1 gets also referenced from outside while you may not need B any more that is then the things become more interesting.
- londons_explore 8y agoDepends how they implement value types. They might simply say 'you can't have a reference to a value type'. You either embed it in your class, or you copy it's value.