# CacheUtil (LWJGL API)
Date: 2015-07-28

## org.lwjgl.util.mapped
Class CacheUtil

    java.lang.Object
      org.lwjgl.util.mapped.CacheUtil

    public final class CacheUtil

extends java.lang.Object

This class provides utility methods for allocating cache-line-aligned NIO buffers. The CPU cache line size is detected using a micro-benchmark that exploits the performation degredation that occurs when different threads write to different locations of the same cache line. The detection should be reasonably robust on both the server and client VM, but there are a few system properties that can be used to tune it.

Author:
  Spasi

Method Summary
`static java.nio.ByteBuffer` `createByteBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned bytebuffer with the specified size.
`static java.nio.CharBuffer` `createCharBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned charbuffer with the specified number of elements.
`static java.nio.DoubleBuffer` `createDoubleBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned doublebuffer with the specified number of elements.
`static java.nio.FloatBuffer` `createFloatBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned floatbuffer with the specified number of elements.
`static java.nio.IntBuffer` `createIntBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned intbuffer with the specified number of elements.
`static java.nio.LongBuffer` `createLongBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned longbuffer with the specified number of elements.
`static PointerBuffer` `createPointerBuffer(int size)` Construct a cache-line-aligned PointerBuffer with the specified number of elements.
`static java.nio.ShortBuffer` `createShortBuffer(int size)` Construct a direct, native-ordered and cache-line-aligned shortbuffer with the specified number of elements.
`static int` `getCacheLineSize()` Returns the CPU cache line size, in number of bytes.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getCacheLineSize

    public static int getCacheLineSize()

  Returns the CPU cache line size, in number of bytes.

  Returns:
    the cache line size

### createByteBuffer

    public static java.nio.ByteBuffer createByteBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned bytebuffer with the specified size.

  Parameters:
    `size` - The size, in bytes
  Returns:
    a ByteBuffer

### createShortBuffer

    public static java.nio.ShortBuffer createShortBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned shortbuffer with the specified number of elements.

  Parameters:
    `size` - The size, in shorts
  Returns:
    a ShortBuffer

### createCharBuffer

    public static java.nio.CharBuffer createCharBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned charbuffer with the specified number of elements.

  Parameters:
    `size` - The size, in chars
  Returns:
    an CharBuffer

### createIntBuffer

    public static java.nio.IntBuffer createIntBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned intbuffer with the specified number of elements.

  Parameters:
    `size` - The size, in ints
  Returns:
    an IntBuffer

### createLongBuffer

    public static java.nio.LongBuffer createLongBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned longbuffer with the specified number of elements.

  Parameters:
    `size` - The size, in longs
  Returns:
    an LongBuffer

### createFloatBuffer

    public static java.nio.FloatBuffer createFloatBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned floatbuffer with the specified number of elements.

  Parameters:
    `size` - The size, in floats
  Returns:
    a FloatBuffer

### createDoubleBuffer

    public static java.nio.DoubleBuffer createDoubleBuffer(int size)

  Construct a direct, native-ordered and cache-line-aligned doublebuffer with the specified number of elements.

  Parameters:
    `size` - The size, in floats
  Returns:
    a FloatBuffer

### createPointerBuffer

    public static PointerBuffer createPointerBuffer(int size)

  Construct a cache-line-aligned PointerBuffer with the specified number of elements.

  Parameters:
    `size` - The size, in memory addresses
  Returns:
    a PointerBuffer

Copyright © 2002-2009 lwjgl.org. All Rights Reserved.