
Allocates memory outside the heap, providing interfaces for read and write operations. Allows memory allocation and transfer to raw sinks, optimizing performance.
The Grid is a tiny library which contains memory and file functionality.
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:grid:0.1.4")
}
...
}
}
interface Memory {
fun writeBytes(bytes: ByteArray, offset: Int)
fun size(): Int
fun readBytes(offset: Int, length: Int): ByteArray
fun transferTo(sink: RawSink) {
rawSource().buffered().transferTo(sink)
}
fun rawSource(): RawSource
}
interface RandomAccessFile : AutoCloseable {
fun read(position: Long, bytes: ByteArray) : Int
fun writeBoolean(position: Long, boolean: Boolean)
fun readBytes(position: Long, bytes: ByteArray, offset: Int = 0, length: Int = bytes.size)
fun writeBytes(position: Long, bytes: ByteArray, offset: Int = 0, length: Int = bytes.size)
fun writeMemory(position: Long, memory: Memory)
fun transferTo(position: Long, sink: Sink, length: Long)
override fun close()
}
fun allocateMemory(size: Int): Memory {...}
fun allocateMemory(bytes: ByteArray): Memory {...}
fun allocateMemory(path: Path): Memory {...}
fun randomAccessFile(path:Path): RandomAccessFile {...}
The Grid is a tiny library which contains memory and file functionality.
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:grid:0.1.4")
}
...
}
}
interface Memory {
fun writeBytes(bytes: ByteArray, offset: Int)
fun size(): Int
fun readBytes(offset: Int, length: Int): ByteArray
fun transferTo(sink: RawSink) {
rawSource().buffered().transferTo(sink)
}
fun rawSource(): RawSource
}
interface RandomAccessFile : AutoCloseable {
fun read(position: Long, bytes: ByteArray) : Int
fun writeBoolean(position: Long, boolean: Boolean)
fun readBytes(position: Long, bytes: ByteArray, offset: Int = 0, length: Int = bytes.size)
fun writeBytes(position: Long, bytes: ByteArray, offset: Int = 0, length: Int = bytes.size)
fun writeMemory(position: Long, memory: Memory)
fun transferTo(position: Long, sink: Sink, length: Long)
override fun close()
}
fun allocateMemory(size: Int): Memory {...}
fun allocateMemory(bytes: ByteArray): Memory {...}
fun allocateMemory(path: Path): Memory {...}
fun randomAccessFile(path:Path): RandomAccessFile {...}