Package org.lwjgl.util.mapped
Class CacheUtil
- java.lang.Object
-
- org.lwjgl.util.mapped.CacheUtil
-
public final class CacheUtil extends 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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ByteBuffercreateByteBuffer(int size)Construct a direct, native-ordered and cache-line-aligned bytebuffer with the specified size.static CharBuffercreateCharBuffer(int size)Construct a direct, native-ordered and cache-line-aligned charbuffer with the specified number of elements.static DoubleBuffercreateDoubleBuffer(int size)Construct a direct, native-ordered and cache-line-aligned doublebuffer with the specified number of elements.static FloatBuffercreateFloatBuffer(int size)Construct a direct, native-ordered and cache-line-aligned floatbuffer with the specified number of elements.static IntBuffercreateIntBuffer(int size)Construct a direct, native-ordered and cache-line-aligned intbuffer with the specified number of elements.static LongBuffercreateLongBuffer(int size)Construct a direct, native-ordered and cache-line-aligned longbuffer with the specified number of elements.static PointerBuffercreatePointerBuffer(int size)Construct a cache-line-aligned PointerBuffer with the specified number of elements.static ShortBuffercreateShortBuffer(int size)Construct a direct, native-ordered and cache-line-aligned shortbuffer with the specified number of elements.static intgetCacheLineSize()Returns the CPU cache line size, in number of bytes.
-
-
-
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 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 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 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 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 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 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 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
-
-