Java FloatBuffer Create createFloatBuffer(float[] array)

Here you can find the source of createFloatBuffer(float[] array)

Description

create Float Buffer

License

Open Source License

Declaration

public static FloatBuffer createFloatBuffer(float[] array) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import java.util.ArrayList;
import java.util.HashMap;

public class Main {
    private static HashMap<Integer, ArrayList<FloatBuffer>> floatBufferQueue;

    public static FloatBuffer createFloatBuffer(float[] array) {
        FloatBuffer result = genFloatBuffer(array.length << 2);
        result.put(array).flip();//from w  w  w  .ja v  a 2  s .  c  o  m
        return result;
    }

    private static FloatBuffer genFloatBuffer(int size) {
        ArrayList<FloatBuffer> bufferList = floatBufferQueue.get(size);
        if (bufferList != null && bufferList.size() > 0) {
            FloatBuffer buffer = bufferList.remove(bufferList.size() - 1);
            return buffer;
        }
        return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder()).asFloatBuffer();
    }
}

Related

  1. createFloatBuffer(FloatBuffer buffer)
  2. createFloatBuffer(int limit)
  3. createFloatBuffer(int numFloats)
  4. createFloatBuffer(int size)