forked from kscience/kmath
1.0 KiB
1.0 KiB
Buffers
Buffer is one of main building blocks of kmath. It is a basic interface allowing random-access read and write (
with MutableBuffer). There are different types of buffers:
- Primitive buffers wrapping like
DoubleBufferwhich are wrapping primitive arrays. - Boxing
ListBufferwrapping a list - Functionally defined
VirtualBufferwhich does not hold a state itself, but provides a function to calculate value MemoryBufferallows direct allocation of objects in continuous memory block.
Some kmath features require a BufferFactory class to operate properly. A general convention is to use functions
defined in
Buffer and MutableBuffer companion classes. For example factory Buffer.Companion::auto in most cases creates the
most suitable buffer for given reified type (for types with custom memory buffer it still better to use their
own MemoryBuffer.create() factory).
Buffer performance
One should avoid using default boxing buffer wherever it is possible. Try to use primitive buffers or memory buffers instead.