Example usage for java.nio ByteBuffer allocateDirect

List of usage examples for java.nio ByteBuffer allocateDirect

Introduction

In this page you can find the example usage for java.nio ByteBuffer allocateDirect.

Prototype

public static ByteBuffer allocateDirect(int capacity) 

Source Link

Document

Creates a direct byte buffer based on a newly allocated memory block.

Usage

From source file:Main.java

public static IntBuffer transportArrayToNativeBuffer(int[] iArray) {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(iArray.length * 4);
    byteBuffer.order(ByteOrder.nativeOrder());
    return (IntBuffer) byteBuffer.asIntBuffer().put(iArray).position(0);
}

From source file:Main.java

public static IntBuffer createIntBuffer(int count) {
    ByteBuffer data = ByteBuffer.allocateDirect(count * 4);
    data.order(ByteOrder.nativeOrder());
    IntBuffer p1 = data.asIntBuffer();
    return p1;/*  www.ja  v  a  2s.c  o  m*/
}

From source file:Main.java

public static FloatBuffer createFloatBuffer(float[] coords) {
    // Allocate a direct ByteBuffer, using 4 bytes per float, and copy coords into it.
    ByteBuffer bb = ByteBuffer.allocateDirect(coords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(coords);//from   w  w  w  .  j  a va 2s .co  m
    fb.position(0);
    return fb;
}

From source file:Main.java

/**
 * Make a FloatBuffer from an array of floats
 * //from   w  w w . j  a va 2 s.co m
 * @param f
 *            The array
 * @return the FloatBuffer
 */
public static FloatBuffer makeFloatBuffer(float[] f) {
    ByteBuffer bytBuffer = ByteBuffer.allocateDirect(f.length * 4);
    bytBuffer.order(ByteOrder.nativeOrder());

    FloatBuffer floatBuffer = bytBuffer.asFloatBuffer();
    floatBuffer.put(f);
    floatBuffer.position(0);

    return floatBuffer;
}

From source file:Main.java

public static IntBuffer allocateInttBuffer(int capacity) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asIntBuffer();
}

From source file:Main.java

public static FloatBuffer allocateFloatBuffer(int capacity) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asFloatBuffer();
}

From source file:Main.java

public static ShortBuffer allocateShortBuffer(int capacity) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asShortBuffer();
}

From source file:Main.java

public static ShortBuffer toShortBuffer(short[] values) {
    final ByteBuffer vbb = ByteBuffer.allocateDirect(values.length * 2);
    vbb.order(ByteOrder.nativeOrder());
    final ShortBuffer buffer = vbb.asShortBuffer();
    buffer.put(values);//  ww  w .j  av  a2  s . c  o m
    buffer.position(0);
    return buffer;
}

From source file:Main.java

public static IntBuffer allocateInttBuffer(int capacity) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asIntBuffer();
}

From source file:Main.java

public static FloatBuffer allocateFloatBuffer(int capacity) {
    ByteBuffer vbb = ByteBuffer.allocateDirect(capacity);
    vbb.order(ByteOrder.nativeOrder());
    return vbb.asFloatBuffer();
}