Top Description Fields Constructors Methods
org.lwjgl.util.mapped

public final Class CacheUtil

extends Object
Class Inheritance
Imports
org.lwjgl.LWJGLUtil, .MemoryUtil, .PointerBuffer, java.nio.*

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

Field Summary

Modifier and TypeField and Description
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ByteBuffer

Returns:

a ByteBuffer
createByteBuffer
(int
The size, in bytes
size
)

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

public static CharBuffer

Returns:

an CharBuffer
createCharBuffer
(int
The size, in chars
size
)

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

public static DoubleBuffer

Returns:

a FloatBuffer
createDoubleBuffer
(int
The size, in floats
size
)

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

public static FloatBuffer

Returns:

a FloatBuffer
createFloatBuffer
(int
The size, in floats
size
)

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

public static IntBuffer

Returns:

an IntBuffer
createIntBuffer
(int
The size, in ints
size
)

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

public static LongBuffer

Returns:

an LongBuffer
createLongBuffer
(int
The size, in longs
size
)

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

public static PointerBuffer

Returns:

a PointerBuffer
createPointerBuffer
(int
The size, in memory addresses
size
)

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

public static ShortBuffer

Returns:

a ShortBuffer
createShortBuffer
(int
The size, in shorts
size
)

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

public static int

Returns:

the cache line size
getCacheLineSize
()

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CACHE_LINE_SIZEback to summary
private static final int CACHE_LINE_SIZE

Constructor Detail

CacheUtilback to summary
private CacheUtil()

Method Detail

createByteBufferback to summary
public static ByteBuffer createByteBuffer(int size)

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

Parameters
size:int

The size, in bytes

Returns:ByteBuffer

a ByteBuffer

createCharBufferback to summary
public static CharBuffer createCharBuffer(int size)

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

Parameters
size:int

The size, in chars

Returns:CharBuffer

an CharBuffer

createDoubleBufferback to summary
public static DoubleBuffer createDoubleBuffer(int size)

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

Parameters
size:int

The size, in floats

Returns:DoubleBuffer

a FloatBuffer

createFloatBufferback to summary
public static FloatBuffer createFloatBuffer(int size)

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

Parameters
size:int

The size, in floats

Returns:FloatBuffer

a FloatBuffer

createIntBufferback to summary
public static IntBuffer createIntBuffer(int size)

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

Parameters
size:int

The size, in ints

Returns:IntBuffer

an IntBuffer

createLongBufferback to summary
public static LongBuffer createLongBuffer(int size)

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

Parameters
size:int

The size, in longs

Returns:LongBuffer

an LongBuffer

createPointerBufferback to summary
public static PointerBuffer createPointerBuffer(int size)

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

Parameters
size:int

The size, in memory addresses

Returns:PointerBuffer

a PointerBuffer

createShortBufferback to summary
public static ShortBuffer createShortBuffer(int size)

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

Parameters
size:int

The size, in shorts

Returns:ShortBuffer

a ShortBuffer

getCacheLineSizeback to summary
public static int getCacheLineSize()

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

Returns:int

the cache line size