Skip to content

OpaquePointerArrayBuffer

Represents a native array buffer backed by an opaque C pointer, providing direct access to unmanaged memory for efficient interop with native C libraries. This class wraps a raw C pointer (COpaquePointer) and manages the lifecycle of the allocated memory. It implements the `ArrayBuffer` interface to provide a unified API for buffer operations while allowing direct manipulation of native memory. The buffer automatically manages memory allocation and deallocation using Kotlin/Native's Arena or manual memory management. This is particularly useful when interfacing with WebGPU or other graphics APIs that expect native memory pointers. #### Parameters - pointer: The opaque C pointer to the native memory - size: The size of the buffer in bytes - ownsMemory: Whether this buffer owns the memory and should free it on cleanup

Properties

pointer

**Parameters** - pointer: The opaque C pointer to the native memory

size

open override val size: ULong
**Parameters** - size: The size of the buffer in bytes

Functions

getByte

open override fun getByte(offset: ULong): Byte
Reads a byte at the specified offset. **Return** the byte value **Parameters** - offset: the byte offset

getDouble

open override fun getDouble(offset: ULong): Double
Reads a double at the specified offset. **Return** the double value **Parameters** - offset: the byte offset (must be aligned to 8 bytes)

getFloat

open override fun getFloat(offset: ULong): Float
Reads a float at the specified offset. **Return** the float value **Parameters** - offset: the byte offset (must be aligned to 4 bytes)

getInt

open override fun getInt(offset: ULong): Int
Reads an int at the specified offset. **Return** the int value **Parameters** - offset: the byte offset (must be aligned to 4 bytes)

getShort

open override fun getShort(offset: ULong): Short
Reads a short at the specified offset. **Return** the short value **Parameters** - offset: the byte offset (must be aligned to 2 bytes)

getUByte

open override fun getUByte(offset: ULong): UByte
Reads an unsigned byte at the specified offset. **Return** the unsigned byte value **Parameters** - offset: the byte offset

getUInt

open override fun getUInt(offset: ULong): UInt
Reads an unsigned int at the specified offset. **Return** the unsigned int value **Parameters** - offset: the byte offset (must be aligned to 4 bytes)

getUShort

open override fun getUShort(offset: ULong): UShort
Reads an unsigned short at the specified offset. **Return** the unsigned short value **Parameters** - offset: the byte offset (must be aligned to 2 bytes)

setByte

open override fun setByte(offset: ULong, value: Byte)
Writes a byte at the specified offset. **Parameters** - offset: the byte offset - value: the byte value to write

setBytes

open override fun setBytes(offset: ULong, array: ByteArray)
Writes a ByteArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing - array: the byte array to write

setDouble

open override fun setDouble(offset: ULong, value: Double)
Writes a double at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 8 bytes) - value: the double value to write

setDoubles

open override fun setDoubles(offset: ULong, array: DoubleArray)
Writes a DoubleArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 8 bytes) - array: the double array to write

setFloat

open override fun setFloat(offset: ULong, value: Float)
Writes a float at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 4 bytes) - value: the float value to write

setFloats

open override fun setFloats(offset: ULong, array: FloatArray)
Writes a FloatArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 4 bytes) - array: the float array to write

setInt

open override fun setInt(offset: ULong, value: Int)
Writes an int at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 4 bytes) - value: the int value to write

setInts

open override fun setInts(offset: ULong, array: IntArray)
Writes an IntArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 4 bytes) - array: the int array to write

setShort

open override fun setShort(offset: ULong, value: Short)
Writes a short at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 2 bytes) - value: the short value to write

setShorts

open override fun setShorts(offset: ULong, array: ShortArray)
Writes a ShortArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 2 bytes) - array: the short array to write

setUByte

open override fun setUByte(offset: ULong, value: UByte)
Writes an unsigned byte at the specified offset. **Parameters** - offset: the byte offset - value: the unsigned byte value to write

setUBytes

open override fun setUBytes(offset: ULong, array: UByteArray)
Writes a UByteArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing - array: the unsigned byte array to write

setUInt

open override fun setUInt(offset: ULong, value: UInt)
Writes an unsigned int at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 4 bytes) - value: the unsigned int value to write

setUInts

open override fun setUInts(offset: ULong, array: UIntArray)
Writes a UIntArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 4 bytes) - array: the unsigned int array to write

setUShort

open override fun setUShort(offset: ULong, value: UShort)
Writes an unsigned short at the specified offset. **Parameters** - offset: the byte offset (must be aligned to 2 bytes) - value: the unsigned short value to write

setUShorts

open override fun setUShorts(offset: ULong, array: UShortArray)
Writes a UShortArray into the buffer at the specified offset. **Parameters** - offset: the byte offset where to start writing (must be aligned to 2 bytes) - array: the unsigned short array to write

toByteArray

open override fun toByteArray(): ByteArray
Converts the buffer to a ByteArray. **Return** a ByteArray containing the buffer's data

toDoubleArray

open override fun toDoubleArray(): DoubleArray
Converts the buffer to a DoubleArray. **Return** a DoubleArray containing the buffer's data (size must be multiple of 8)

toFloatArray

open override fun toFloatArray(): FloatArray
Converts the buffer to a FloatArray. **Return** a FloatArray containing the buffer's data (size must be multiple of 4)

toIntArray

open override fun toIntArray(): IntArray
Converts the buffer to an IntArray. **Return** an IntArray containing the buffer's data (size must be multiple of 4)

toShortArray

open override fun toShortArray(): ShortArray
Converts the buffer to a ShortArray. **Return** a ShortArray containing the buffer's data (size must be multiple of 2)

toUByteArray

open override fun toUByteArray(): UByteArray
Converts the buffer to a UByteArray. **Return** a UByteArray containing the buffer's data

toUIntArray

open override fun toUIntArray(): UIntArray
Converts the buffer to a UIntArray. **Return** a UIntArray containing the buffer's data (size must be multiple of 4)

toUShortArray

open override fun toUShortArray(): UShortArray
Converts the buffer to a UShortArray. **Return** a UShortArray containing the buffer's data (size must be multiple of 2)