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