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


Java Unsafe.copyMemory方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:CopyMemory.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:CopyMemory.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:CopyMemory.java

示例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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:CopyMemory.java


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