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


Java Buffer.isDirect方法代码示例

本文整理汇总了Java中java.nio.Buffer.isDirect方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.isDirect方法的具体用法?Java Buffer.isDirect怎么用?Java Buffer.isDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.Buffer的用法示例。


在下文中一共展示了Buffer.isDirect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkBufferDirect

import java.nio.Buffer; //导入方法依赖的package包/类
private static void checkBufferDirect(Buffer buffer, String type) {
    if (buffer == null) {
        return;
    }
    if (!buffer.isDirect()) {
        throwIAEOrLogError("buffer is not direct. Buffers created via " + type + ".allocate() or " + type + ".wrap() are not supported. " + "Use BufferUtils.create" + type + "() instead.");
    } else if (buffer.remaining() == 0) {
        throwIAEOrLogError("buffer has no remaining elements. Did you forget to flip()/rewind() it?");
    }
}
 
开发者ID:LWJGLX,项目名称:debug,代码行数:11,代码来源:RT.java

示例2: release

import java.nio.Buffer; //导入方法依赖的package包/类
/**
 * Direct {@link ByteBuffer}s are stored in system memory, and released when garbage collection occurs
 * and the buffer is deemed to be unreachable, following vanilla garbage collection procedures. At that
 * point, a special finalizer, "Cleaner" runs to de-allocate the system memory (and in the case of
 * {@link MappedByteBuffer}s, unmap the file).
 * <p/>
 * However, if garbage collection does not occur, the system memory remains taken, and the {@link MappedByteBuffer}
 * (if applicable) remains mapped, meaning system level operations cannot occur in other processes.
 * <p/>
 * This method seeks to release a direct {@link ByteBuffer} early by calling well known reflective code
 * in a best-attempt fashion. In the case that this reflective code is not present, the method
 * finishes with a log message, and normal Java practice takes over; i.e. the buffer is not released
 * and if it's a {@link MappedByteBuffer} the file is not unmapped, until later GC occurs or the
 * JVM is terminated.
 *
 * @param bb
 * @throws NullPointerException     If bb is null.
 * @throws IllegalArgumentException If bb is not a "direct" {@link ByteBuffer}
 */
public static void release(Buffer bb)
{

    if (bb == null)
    {
        throw new NullPointerException(ByteBuffer.class.getSimpleName() + " should not be null");
    }
    if (!bb.isDirect())
    {
        throw new IllegalArgumentException(bb.getClass().getName() + " is not direct.");
    }

    releaseStrategy.release(bb);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:34,代码来源:DirectByteBufferUtils.java


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