Creates a new Buffer instance.
Configuration object for the buffer
The underlying ArrayBuffer or Uint8Array to wrap
The byte alignment requirement for memory allocation
The total byte length of the buffer
A descriptive name for the buffer
Gets the total byte length of the buffer.
The total capacity of the buffer in bytes
Gets the byte offset of this buffer within the raw ArrayBuffer. This is useful when the buffer is a view into a larger ArrayBuffer.
The byte offset within the raw ArrayBuffer
Gets the name of the buffer.
The current name of the buffer
Sets the name of the buffer.
The new name for the buffer
Gets the number of bytes currently allocated from this buffer.
The number of bytes that have been taken from the buffer
Creates a typed array view into the buffer at a specific offset. This method provides direct access to the buffer data as a typed array, which is useful for reading and writing numeric data efficiently.
The offset in 4-byte units from the start of the buffer
The composition type (scalar, vector, matrix, etc.)
The component type (float, int, etc.)
The number of elements to include in the typed array (default: 100)
A typed array view into the buffer data
Checks if this buffer uses the same underlying ArrayBuffer as another buffer. This is useful for determining if two Buffer instances share the same memory.
The other buffer to compare with
True if both buffers use the same underlying ArrayBuffer, false otherwise
Creates a new BufferView from the available space in this buffer. This method allocates a portion of the buffer and returns a BufferView that provides typed access to that memory region.
Configuration for the BufferView to create
The number of bytes needed for the BufferView
The stride between elements in bytes
A Result containing either the created BufferView or an error with buffer state information
Creates a new BufferView at a specific byte offset within this buffer. Unlike takeBufferView, this method allows you to specify the exact offset where the BufferView should be created, which is useful for accessing pre-defined memory layouts.
Configuration for the BufferView to create
The number of bytes needed for the BufferView
The specific byte offset within the buffer where the BufferView should start
The stride between elements in bytes
A Result containing either the created BufferView or an error
A Buffer class that manages memory allocation and provides BufferView creation functionality. This class wraps an ArrayBuffer and manages byte allocation with alignment considerations. It tracks the used bytes and provides methods to create BufferView instances from the underlying buffer.
Example