本文整理匯總了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);
}
}