Buffer

Region of native memory that can be read and written.

This class provides no thread-safety of its own. Synchronize externally if the same instance is accessed from more than one thread.

This buffer must be closed once no longer needed to release the memory it holds. Unless documented otherwise, every member throws IllegalStateException once it is closed.

Types

Link copied to clipboard
object Companion

Provides factory functions for allocating a Buffer.

Properties

Link copied to clipboard

Size of the memory region in bytes.

Functions

Link copied to clipboard
open override fun close()

Releases the memory this buffer holds. Calling this again on an already closed buffer has no effect.

Link copied to clipboard
fun read(destination: ByteArray, size: Int = destination.size, sourceOffset: Long = 0, destinationOffset: Int = 0)

Reads size bytes from the native memory block into destination.

Link copied to clipboard
fun ReadableBuffer.read(size: Int, offset: Long = 0): ByteArray

Reads size bytes from the native memory block, starting at offset, and returns them as a new ByteArray.

Link copied to clipboard

Reads this whole buffer and returns it as a new ByteArray, up to Int.MAX_VALUE bytes.

Link copied to clipboard

Reads this whole buffer and returns it as a new ByteArray.

Link copied to clipboard
fun resize(newSize: Int)
fun resize(newSize: Long)

Resizes this buffer to newSize. The buffer is left untouched if allocation fails.

Link copied to clipboard
fun write(source: ByteArray, size: Int, sourceOffset: Int = 0, destinationOffset: Long = 0)

Writes size bytes from source into the native memory block.