Java ByteBuffer Allocate allocate(int size)

Here you can find the source of allocate(int size)

Description

allocate

License

Open Source License

Declaration

public static ByteBuffer allocate(int size) 

Method Source Code

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

import java.nio.ByteBuffer;

public class Main {
    private static final int DIRECT_THRESHOLD = 10240;

    public static ByteBuffer allocate(int size) {
        // allocateDirect is pretty slow when used frequently, use it for larger
        // buffers only
        if (size > DIRECT_THRESHOLD) {
            return ByteBuffer.allocateDirect(size);
        } else {//from w ww .j av a2 s. c  om
            try {
                return ByteBuffer.allocate(size);
            } catch (OutOfMemoryError ex) {
                // not enough space in the heap, try direct allocation instead
                return ByteBuffer.allocateDirect(size);
            }
        }
    }
}

Related

  1. allocate(int capacity)
  2. allocate(int capacity, boolean direct)
  3. allocate(int length)
  4. allocate(int length, byte fillwith)
  5. allocate(int size)
  6. allocateBuffer(int size, boolean isDirect)
  7. allocateDirect(int capacity)
  8. allocateDirectBuffer(int size)
  9. allocateDirectInt(int size)