Kotlin / KEEP

Kotlin Evolution and Enhancement Process
Apache License 2.0
3.29k stars 357 forks source link

KEEP for multi-field value classes #339

Open zhelenskiy opened 1 year ago

soywiz commented 1 year ago

There is another use-case I would like to share:

Here: https://docs.korge.org/ktcc/

There I'm doing black magic tricks that are really dirty to avoid allocations, and the code looks ugly. Being able to have something like:

value class MyPointer(val buffer: Buffer, val offset: Int) {
  var x: Double get() = buffer.getDouble(0); set(value) { buffer.setDouble(0, value) }
  var y: Double get() = buffer.getDouble(8); set(value) { buffer.setDouble(8, value) }
}

That would help to have C-like pointers: an array or buffer + offset (+ maybe optionally size)