Skip to content

Instantly share code, notes, and snippets.

@sharrissf
sharrissf / gist:700690
Created November 15, 2010 17:58
Direct Memory vs On Heap in Java
import java.nio.ByteBuffer;
import java.util.Random;
public class BufferPerformanceComparison {
public final static int MEGA_BYTE = 1024 * 1024;
public final static long GIGA_BYTE = MEGA_BYTE * 1024;
private final ByteBuffer heapByteBuffer;
private final ByteBuffer offHeapByteBuffer;
private final long dataToLoad;
private final int bufferSize;