当前位置: 首页>>代码示例>>Java>>正文


Java MemoryUtil.getAddress方法代码示例

本文整理汇总了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;
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:21,代码来源:MappedHelper.java

示例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);
}
 
开发者ID:CodeConglomerate,项目名称:TeacherSmash,代码行数:27,代码来源:MappedObjectBench.java

示例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);
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:18,代码来源:MappedObjectTests3.java

示例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());
}
 
开发者ID:Superloup10,项目名称:Wolf_game,代码行数:20,代码来源:CacheUtil.java

示例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;
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:12,代码来源:CacheLineSize.java

示例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);
}
 
开发者ID:Superloup10,项目名称:Wolf_game,代码行数:34,代码来源:MappedObjectTests3.java

示例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();
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:14,代码来源:CacheLineSize.java

示例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);
	}
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:14,代码来源:MappedObjectTests4.java

示例9: getInt

import org.lwjgl.MemoryUtil; //导入方法依赖的package包/类
static long getInt(final int value) {
	return MemoryUtil.getAddress(getBufferInt().put(0, value), 0);
}
 
开发者ID:CodeConglomerate,项目名称:TeacherSmash,代码行数:4,代码来源:APIUtil.java

示例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);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:13,代码来源:APIUtil.java

示例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);
}
 
开发者ID:Arcbe,项目名称:GPVM,代码行数:13,代码来源:APIUtil.java


注:本文中的org.lwjgl.MemoryUtil.getAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。