本文整理汇总了Java中sun.misc.Unsafe.setMemory方法的典型用法代码示例。如果您正苦于以下问题:Java Unsafe.setMemory方法的具体用法?Java Unsafe.setMemory怎么用?Java Unsafe.setMemory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.misc.Unsafe
的用法示例。
在下文中一共展示了Unsafe.setMemory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetByteArray
import sun.misc.Unsafe; //导入方法依赖的package包/类
private static void testSetByteArray(Unsafe unsafe) throws Exception {
System.out.println("Testing setMemory() for byte[]...");
byte[] b = new byte[BUFFER_SIZE];
for (int i = 0; i < N; i++) {
set(b, 0, BUFFER_SIZE, FILLER);
int ofs = random.nextInt(BUFFER_SIZE / 2);
int len = random.nextInt(BUFFER_SIZE / 2);
int val = random.nextInt(256);
unsafe.setMemory(b, Unsafe.ARRAY_BYTE_BASE_OFFSET + ofs, len, (byte)val);
check(b, 0, ofs - 1, FILLER);
check(b, ofs, len, val);
check(b, ofs + len, BUFFER_SIZE - (ofs + len), FILLER);
}
}
示例2: testSetRawMemory
import sun.misc.Unsafe; //导入方法依赖的package包/类
private static void testSetRawMemory(Unsafe unsafe) throws Exception {
System.out.println("Testing setMemory() for raw memory...");
long b = getMemory(BUFFER_SIZE);
for (int i = 0; i < N; i++) {
set(unsafe, b, 0, BUFFER_SIZE, FILLER);
int ofs = random.nextInt(BUFFER_SIZE / 2);
int len = random.nextInt(BUFFER_SIZE / 2);
int val = random.nextInt(256);
unsafe.setMemory(null, b + ofs, len, (byte)val);
check(unsafe, b, 0, ofs - 1, FILLER);
check(unsafe, b, ofs, len, val);
check(unsafe, b, ofs + len, BUFFER_SIZE - (ofs + len), FILLER);
}
}
示例3: main
import sun.misc.Unsafe; //导入方法依赖的package包/类
public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
Unsafe u = (Unsafe) f.get(null);
u.setMemory(0, 42, (byte) 0xFF);
}