本文整理汇总了Java中org.lwjgl.MemoryUtil.getAddress方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryUtil.getAddress方法的具体用法?Java MemoryUtil.getAddress怎么用?Java MemoryUtil.getAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.MemoryUtil
的用法示例。
在下文中一共展示了MemoryUtil.getAddress方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
public static void setup(MappedObject mo, ByteBuffer buffer, int align, int sizeof) {
if ( LWJGLUtil.CHECKS && mo.baseAddress != 0L )
throw new IllegalStateException("this method should not be called by user-code");
if ( LWJGLUtil.CHECKS && !buffer.isDirect() )
throw new IllegalArgumentException("bytebuffer must be direct");
mo.preventGC = buffer;
if ( LWJGLUtil.CHECKS && align <= 0 )
throw new IllegalArgumentException("invalid alignment");
if ( LWJGLUtil.CHECKS && (sizeof <= 0 || sizeof % align != 0) )
throw new IllegalStateException("sizeof not a multiple of alignment");
long addr = MemoryUtil.getAddress(buffer);
if ( LWJGLUtil.CHECKS && addr % align != 0 )
throw new IllegalStateException("buffer address not aligned on " + align + " bytes");
mo.baseAddress = mo.viewAddress = addr;
}
示例2: benchmarkUnsafe
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static void benchmarkUnsafe() {
final int runs = 64;
final int iterations = 64 * 1024;
ByteBuffer bb = ByteBuffer.allocateDirect(200);
long addr = MemoryUtil.getAddress(bb);
long[] took = new long[runs];
for ( int run = 0; run < runs; run++ ) {
long t0 = System.nanoTime();
for ( int iteration = 0; iteration < iterations; iteration++ ) {
fput(13, addr + (1 * 3 + 0) * 4);
fput(fget(addr + (1 * 3 + 1) * 4) + fget(addr + (1 * 3 + 1) * 4) * fget(addr + (1 * 3 + 0) * 4) + 0.3f, addr + (1 * 3 + 1) * 4);
fput(fget(addr + (1 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4) + fget(addr + (1 * 3 + 0) * 4) + 0.3f, addr + (1 * 3 + 2) * 4);
fput(fget(addr + (2 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4) + fget(addr + (1 * 3 + 0) * 4), addr + (2 * 3 + 2) * 4);
fput(fget(addr + (3 * 3 + 2) * 4) + fget(addr + (2 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4), addr + (3 * 3 + 2) * 4);
}
long t1 = System.nanoTime();
took[run] = t1 - t0;
}
Arrays.sort(took);
System.out.println("unsafe took: " + took[took.length / 2] / 1024 + "us");
System.out.println(bb);
}
示例3: testConstructor
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static void testConstructor() {
int capacity = 1024;
ByteBuffer bb = ByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder());
long address = MemoryUtil.getAddress(bb);
MappedFloat mf = MappedFloat.map(address, capacity);
assert (address == mf.baseAddress);
assert (mf.value == 0.0f);
mf.view = 1;
assert (mf.value == 0.0f);
mf.runViewConstructor();
assert (mf.value == 4.0f);
Xyz.malloc(3);
}
示例4: createByteBuffer
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
/**
* Construct a direct, native-ordered and cache-line-aligned bytebuffer with the specified size.
*
* @param size The size, in bytes
*
* @return a ByteBuffer
*/
public static ByteBuffer createByteBuffer(int size) {
ByteBuffer buffer = ByteBuffer.allocateDirect(size + CACHE_LINE_SIZE);
// Align to cache line.
if ( MemoryUtil.getAddress(buffer) % CACHE_LINE_SIZE != 0 ) {
// Round up to cache line boundary
buffer.position(CACHE_LINE_SIZE - (int)(MemoryUtil.getAddress(buffer) & (CACHE_LINE_SIZE - 1)));
}
buffer.limit(buffer.position() + size);
return buffer.slice().order(ByteOrder.nativeOrder());
}
示例5: memoryLoop
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static long memoryLoop(final int index, final int repeats, final IntBuffer memory, final int padding) {
final long address = MemoryUtil.getAddress(memory) + (index * padding * 4);
final long time = System.nanoTime();
for ( int i = 0; i < repeats; i++ ) {
// Use volatile access to avoid server VM optimizations.
ivput(ivget(address) + 1, address);
}
return System.nanoTime() - time;
}
示例6: testMappedBuffer
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static void testMappedBuffer() {
int elementCount = 4;
MappedSomething some = MappedSomething.malloc(elementCount);
assert (some.data != some.data);
long addr1 = MemoryUtil.getAddress(some.backingByteBuffer());
ByteBuffer mapped = some.data; // creates new ByteBuffer instance
long addr2 = MemoryUtil.getAddress(mapped);
assert (addr2 - addr1 == 4);
assert (mapped.capacity() == MappedSomething.SIZEOF - 4);
{
assert (some.shared == 0);
assert (mapped.getInt(8) == 0);
some.shared = 1234;
assert (some.shared == 1234);
assert (mapped.getInt(8) == 1234);
}
some.view++;
mapped = some.data; // creates new ByteBuffer instance
long addr3 = MemoryUtil.getAddress(mapped);
assert (addr3 - addr1 == 4 + MappedSomething.SIZEOF);
assert (addr3 - addr2 == 0 + MappedSomething.SIZEOF);
assert (mapped.capacity() == MappedSomething.SIZEOF - 4);
}
示例7: getMemory
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
private static IntBuffer getMemory(final int START_SIZE) {
final int PAGE_SIZE = MappedObjectUnsafe.INSTANCE.pageSize();
final ByteBuffer buffer = ByteBuffer.allocateDirect((START_SIZE * 4) + PAGE_SIZE).order(ByteOrder.nativeOrder());
// Align to page and, consequently, to cache line. Otherwise results will be inconsistent.
if ( MemoryUtil.getAddress(buffer) % PAGE_SIZE != 0 ) {
// Round up to page boundary
buffer.position(PAGE_SIZE - (int)(MemoryUtil.getAddress(buffer) & (PAGE_SIZE - 1)));
}
return buffer.asIntBuffer();
}
示例8: testLocalView
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
private static void testLocalView(MappedSomething some) {
final MappedSomething[] array = some.asArray();
assert (array.length == 5);
final long baseAddress = MemoryUtil.getAddress(some.backingByteBuffer());
for ( int i = 0; i < array.length; i++ ) {
ByteBuffer data = array[i].data;
assert (data.capacity() == (64 - 4));
assert (MemoryUtil.getAddress(data) == baseAddress + i * MappedSomething.SIZEOF + 4);
}
}
示例9: getInt
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static long getInt(final int value) {
return MemoryUtil.getAddress(getBufferInt().put(0, value), 0);
}
示例10: getBuffer
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
/**
* Returns a buffer containing the specified string as bytes, starting at the specified offset.
*
* @param string
*
* @return the String as a ByteBuffer
*/
static long getBuffer(final ContextCapabilities caps, final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(caps, offset + string.length()), string);
buffer.flip();
return MemoryUtil.getAddress(buffer);
}
示例11: getBuffer
import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
/**
* Returns a buffer containing the specified string as bytes, starting at the specified offset.
*
* @param string
*
* @return the String as a ByteBuffer
*/
static long getBuffer(final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
buffer.flip();
return MemoryUtil.getAddress(buffer);
}