This pull requests introduces a new feature to scala-offheap: embedded fields. Rather than storing a reference to another data types, embedded fields let one to completely embed data of one class into another. For example:
@data class Point(x: Int, y: Int)
@data class Segment(@embed start: Point, @embed end: Point)
Here Segment is 16-byte structure that contains two points inside of its data layout. Allocation of Segment like:
Segment(Point(10, 20), Point(30, 40))
Will perform exactly one allocation with corresponding point data written directly into segment-allocated memory. If points are allocated separately the data will be copied over from previous allocations:
val p1 = Point(10, 20)
val p2 = Point(30, 40)
Segment(p1, p2)
Reading an embedded field is just an arithmetic computation of inner pointer, it doesn't actually perform any memory accesses (thus no pointer chasing.)
This pull requests introduces a new feature to scala-offheap: embedded fields. Rather than storing a reference to another data types, embedded fields let one to completely embed data of one class into another. For example:
Here
Segment
is 16-byte structure that contains two points inside of its data layout. Allocation ofSegment
like:Will perform exactly one allocation with corresponding point data written directly into segment-allocated memory. If points are allocated separately the data will be copied over from previous allocations:
Reading an embedded field is just an arithmetic computation of inner pointer, it doesn't actually perform any memory accesses (thus no pointer chasing.)