Package arc.util
Class Buffers
java.lang.Object
arc.util.Buffers
Class with static helper methods to increase the speed of array/direct buffer and direct buffer/direct buffer transfers
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.static void
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.static void
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.static void
Copies numFloats floats from src starting at offset to dst.static void
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.static void
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.static void
Copies the contents of src to dst, starting from the current position of src, copying numElements elements (using the data type of src, no matter the datatype of dst).static void
disposeUnsafeByteBuffer
(ByteBuffer buffer) static int
static long
getUnsafeBufferAddress
(Buffer buffer) Returns the address of the Buffer, it assumes it is an unsafe buffer.static boolean
isUnsafeByteBuffer
(ByteBuffer buffer) static ByteBuffer
newByteBuffer
(int numBytes) static FloatBuffer
newFloatBuffer
(int numFloats) static IntBuffer
newIntBuffer
(int numInts) static ShortBuffer
newShortBuffer
(int numShorts) static ByteBuffer
newUnsafeByteBuffer
(int numBytes) Allocates a new direct ByteBuffer from native heap memory using the native byte order.static ByteBuffer
newUnsafeByteBuffer
(ByteBuffer buffer) Registers the given ByteBuffer as an unsafe ByteBuffer.
-
Constructor Details
-
Buffers
public Buffers()
-
-
Method Details
-
copy
Copies numFloats floats from src starting at offset to dst. Dst is assumed to be a directBuffer
. The method will crash if that is not the case. The position and limit of the buffer are ignored, the copy is placed at position 0 in the buffer. After the copying process the position of the buffer is set to 0 and its limit is set to numFloats * 4 if it is a ByteBuffer and numFloats if it is a FloatBuffer. In case the Buffer is neither a ByteBuffer nor a FloatBuffer the limit is not set. This is an expert method, use at your own risk.- Parameters:
src
- the source arraydst
- the destination buffer, has to be a direct BuffernumFloats
- the number of floats to copyoffset
- the offset in src to start copying from
-
copy
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. TheBuffer
instance'sBuffer.position()
is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.- Parameters:
src
- the source array.srcOffset
- the offset into the source array.dst
- the destination Buffer, its position is used as an offset.numElements
- the number of elements to copy.
-
copy
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. TheBuffer
instance'sBuffer.position()
is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.- Parameters:
src
- the source array.srcOffset
- the offset into the source array.dst
- the destination Buffer, its position is used as an offset.numElements
- the number of elements to copy.
-
copy
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. TheBuffer
instance'sBuffer.position()
is used to define the offset into the Buffer itself. The position and limit will stay the same. The Buffer must be a direct Buffer with native byte order. No error checking is performed.- Parameters:
src
- the source array.srcOffset
- the offset into the source array.numElements
- the number of elements to copy.dst
- the destination Buffer, its position is used as an offset.
-
copy
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. TheBuffer
instance'sBuffer.position()
is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.- Parameters:
src
- the source array.srcOffset
- the offset into the source array.dst
- the destination Buffer, its position is used as an offset.numElements
- the number of elements to copy.
-
copy
Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. TheBuffer
instance'sBuffer.position()
is used to define the offset into the Buffer itself. The position will stay the same, the limit will be set to position + numElements. The Buffer must be a direct Buffer with native byte order. No error checking is performed.- Parameters:
src
- the source array.srcOffset
- the offset into the source array.dst
- the destination Buffer, its position is used as an offset.numElements
- the number of elements to copy.
-
copy
Copies the contents of src to dst, starting from the current position of src, copying numElements elements (using the data type of src, no matter the datatype of dst). The dstBuffer.position()
is used as the writing offset. The position of both Buffers will stay the same. The limit of the src Buffer will stay the same. The limit of the dst Buffer will be set to dst.position() + numElements, where numElements are translated to the number of elements appropriate for the dst Buffer data type. The Buffers must be direct Buffers with native byte order. No error checking is performed.- Parameters:
src
- the source Buffer.dst
- the destination Buffer.numElements
- the number of elements to copy.
-
newFloatBuffer
-
newShortBuffer
-
newByteBuffer
-
newIntBuffer
-
disposeUnsafeByteBuffer
-
isUnsafeByteBuffer
-
newUnsafeByteBuffer
Allocates a new direct ByteBuffer from native heap memory using the native byte order. Needs to be disposed withdisposeUnsafeByteBuffer(ByteBuffer)
. -
getUnsafeBufferAddress
Returns the address of the Buffer, it assumes it is an unsafe buffer.- Parameters:
buffer
- The Buffer to ask the address for.- Returns:
- the address of the Buffer.
-
newUnsafeByteBuffer
Registers the given ByteBuffer as an unsafe ByteBuffer. The ByteBuffer must have been allocated in native code, pointing to a memory region allocated via malloc. Needs to be disposed withdisposeUnsafeByteBuffer(ByteBuffer)
.- Parameters:
buffer
- theByteBuffer
to register- Returns:
- the ByteBuffer passed to the method
-
getAllocatedBytesUnsafe
public static int getAllocatedBytesUnsafe()- Returns:
- the number of bytes allocated with
newUnsafeByteBuffer(int)
-