Here you can find the source of allocate(int size)
public static ByteBuffer allocate(int size)
//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); } } } }