toByteArray

Allocates a new primitive ByteArray with a size equal to this capacity.

  • This is the most performant way to allocate a buffer, as it utilizes native memory allocation where all elements are instantly initialized to 0.

Warning on Truncation: Because Kotlin arrays are strictly indexed by Int, the maximum allowed size is Int.MAX_VALUE- 8 (approximately 2.14 GB). If this capacity exceeds that limit, the resulting array size will be silently truncated to Int.MAX_VALUE.

Return

A new primitive ByteArray filled with zeros.