Package org.lwjgl.util.mapped
Class CacheUtil
java.lang.Object
org.lwjgl.util.mapped.CacheUtil
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
Modifier and TypeMethodDescriptionstatic 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 intReturns the CPU cache line size, in number of bytes.
-
Method Details
-
getCacheLineSize
public static int getCacheLineSize()Returns the CPU cache line size, in number of bytes.- Returns:
- the cache line size
-
createByteBuffer
Construct a direct, native-ordered and cache-line-aligned bytebuffer with the specified size.- Parameters:
size- The size, in bytes- Returns:
- a ByteBuffer
-
createShortBuffer
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
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
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
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
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
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
Construct a cache-line-aligned PointerBuffer with the specified number of elements.- Parameters:
size- The size, in memory addresses- Returns:
- a PointerBuffer
-