Package arc.util

Class Buffers

java.lang.Object
arc.util.Buffers

public final class Buffers extends Object
Class with static helper methods to increase the speed of array/direct buffer and direct buffer/direct buffer transfers
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    copy(byte[] src, int srcOffset, Buffer dst, int numElements)
    Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
    static void
    copy(float[] src, int srcOffset, int numElements, Buffer dst)
    Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
    static void
    copy(float[] src, int srcOffset, Buffer dst, int numElements)
    Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
    static void
    copy(float[] src, Buffer dst, int numFloats, int offset)
    Copies numFloats floats from src starting at offset to dst.
    static void
    copy(int[] src, int srcOffset, Buffer dst, int numElements)
    Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
    static void
    copy(short[] src, int srcOffset, Buffer dst, int numElements)
    Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements.
    static void
    copy(Buffer src, Buffer dst, int numElements)
    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
     
    static int
     
    static long
    Returns the address of the Buffer, it assumes it is an unsafe buffer.
    static boolean
     
    static ByteBuffer
    newByteBuffer(int numBytes)
     
    newFloatBuffer(int numFloats)
     
    static IntBuffer
    newIntBuffer(int numInts)
     
    newShortBuffer(int numShorts)
     
    static ByteBuffer
    newUnsafeByteBuffer(int numBytes)
    Allocates a new direct ByteBuffer from native heap memory using the native byte order.
    static ByteBuffer
    Registers the given ByteBuffer as an unsafe ByteBuffer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Buffers

      public Buffers()
  • Method Details

    • copy

      public static void copy(float[] src, Buffer dst, int numFloats, int offset)
      Copies numFloats floats from src starting at offset to dst. Dst is assumed to be a direct Buffer. 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 array
      dst - the destination buffer, has to be a direct Buffer
      numFloats - the number of floats to copy
      offset - the offset in src to start copying from
    • copy

      public static void copy(byte[] src, int srcOffset, Buffer dst, int numElements)
      Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.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

      public static void copy(short[] src, int srcOffset, Buffer dst, int numElements)
      Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.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

      public static void copy(float[] src, int srcOffset, int numElements, Buffer dst)
      Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.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

      public static void copy(int[] src, int srcOffset, Buffer dst, int numElements)
      Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.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

      public static void copy(float[] src, int srcOffset, Buffer dst, int numElements)
      Copies the contents of src to dst, starting from src[srcOffset], copying numElements elements. The Buffer instance's Buffer.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

      public static void copy(Buffer src, Buffer dst, int numElements)
      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 dst Buffer.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

      public static FloatBuffer newFloatBuffer(int numFloats)
    • newShortBuffer

      public static ShortBuffer newShortBuffer(int numShorts)
    • newByteBuffer

      public static ByteBuffer newByteBuffer(int numBytes)
    • newIntBuffer

      public static IntBuffer newIntBuffer(int numInts)
    • disposeUnsafeByteBuffer

      public static void disposeUnsafeByteBuffer(ByteBuffer buffer)
    • isUnsafeByteBuffer

      public static boolean isUnsafeByteBuffer(ByteBuffer buffer)
    • newUnsafeByteBuffer

      public static ByteBuffer newUnsafeByteBuffer(int numBytes)
      Allocates a new direct ByteBuffer from native heap memory using the native byte order. Needs to be disposed with disposeUnsafeByteBuffer(ByteBuffer).
    • getUnsafeBufferAddress

      public static long getUnsafeBufferAddress(Buffer buffer)
      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

      public static ByteBuffer newUnsafeByteBuffer(ByteBuffer buffer)
      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 with disposeUnsafeByteBuffer(ByteBuffer).
      Parameters:
      buffer - the ByteBuffer to register
      Returns:
      the ByteBuffer passed to the method
    • getAllocatedBytesUnsafe

      public static int getAllocatedBytesUnsafe()
      Returns:
      the number of bytes allocated with newUnsafeByteBuffer(int)