/** * Direct buffers are garbage collected by using a phantom reference and a * reference queue. Every once a while, the JVM checks the reference queue * and cleans the direct buffers. However, as this doesn't happen * immediately after discarding all references to a direct buffer, it's easy * to OutOfMemoryError yourself using direct buffers. **/ public static void destroyDirectBuffer(Buffer toBeDestroyed) { if (!isDirect(toBeDestroyed)) { return; } allocator.destroyDirectBuffer(toBeDestroyed); }
/** * Creates a new ByteBuffer with the same contents as the given ByteBuffer. * The new ByteBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ByteBuffer to copy * @return the copy */ public static ByteBuffer clone(ByteBuffer buf) { if (buf == null) { return null; } buf.rewind(); ByteBuffer copy; if (isDirect(buf)) { copy = createByteBuffer(buf.limit()); } else { copy = ByteBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new ShortBuffer with the same contents as the given * ShortBuffer. The new ShortBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ShortBuffer to copy * @return the copy */ public static ShortBuffer clone(ShortBuffer buf) { if (buf == null) { return null; } buf.rewind(); ShortBuffer copy; if (isDirect(buf)) { copy = createShortBuffer(buf.limit()); } else { copy = ShortBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new FloatBuffer with the same contents as the given * FloatBuffer. The new FloatBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the FloatBuffer to copy * @return the copy */ public static FloatBuffer clone(FloatBuffer buf) { if (buf == null) { return null; } buf.rewind(); FloatBuffer copy; if (isDirect(buf)) { copy = createFloatBuffer(buf.limit()); } else { copy = FloatBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new IntBuffer with the same contents as the given IntBuffer. * The new IntBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the IntBuffer to copy * @return the copy */ public static IntBuffer clone(IntBuffer buf) { if (buf == null) { return null; } buf.rewind(); IntBuffer copy; if (isDirect(buf)) { copy = createIntBuffer(buf.limit()); } else { copy = IntBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new DoubleBuffer with the same contents as the given * DoubleBuffer. The new DoubleBuffer is separate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). * * @param buf * the DoubleBuffer to copy * @return the copy */ public static DoubleBuffer clone(DoubleBuffer buf) { if (buf == null) { return null; } buf.rewind(); DoubleBuffer copy; if (isDirect(buf)) { copy = createDoubleBuffer(buf.limit()); } else { copy = DoubleBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Direct buffers are garbage collected by using a phantom reference and a * reference queue. Every once a while, the JVM checks the reference queue * and cleans the direct buffers. However, as this doesn't happen * immediately after discarding all references to a direct buffer, it's easy * to OutOfMemoryError yourself using direct buffers. **/ public static void destroyDirectBuffer(Buffer toBeDestroyed) { if (!isDirect(toBeDestroyed)) { return; } allocator.destroyDirectBuffer(toBeDestroyed); }
/** * Creates a new ByteBuffer with the same contents as the given ByteBuffer. * The new ByteBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ByteBuffer to copy * @return the copy */ public static ByteBuffer clone(ByteBuffer buf) { if (buf == null) { return null; } buf.rewind(); ByteBuffer copy; if (isDirect(buf)) { copy = createByteBuffer(buf.limit()); } else { copy = ByteBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new ShortBuffer with the same contents as the given * ShortBuffer. The new ShortBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the ShortBuffer to copy * @return the copy */ public static ShortBuffer clone(ShortBuffer buf) { if (buf == null) { return null; } buf.rewind(); ShortBuffer copy; if (isDirect(buf)) { copy = createShortBuffer(buf.limit()); } else { copy = ShortBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new IntBuffer with the same contents as the given IntBuffer. * The new IntBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the IntBuffer to copy * @return the copy */ public static IntBuffer clone(IntBuffer buf) { if (buf == null) { return null; } buf.rewind(); IntBuffer copy; if (isDirect(buf)) { copy = createIntBuffer(buf.limit()); } else { copy = IntBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new FloatBuffer with the same contents as the given * FloatBuffer. The new FloatBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). * * @param buf * the FloatBuffer to copy * @return the copy */ public static FloatBuffer clone(FloatBuffer buf) { if (buf == null) { return null; } buf.rewind(); FloatBuffer copy; if (isDirect(buf)) { copy = createFloatBuffer(buf.limit()); } else { copy = FloatBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }
/** * Creates a new DoubleBuffer with the same contents as the given * DoubleBuffer. The new DoubleBuffer is separate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). * * @param buf * the DoubleBuffer to copy * @return the copy */ public static DoubleBuffer clone(DoubleBuffer buf) { if (buf == null) { return null; } buf.rewind(); DoubleBuffer copy; if (isDirect(buf)) { copy = createDoubleBuffer(buf.limit()); } else { copy = DoubleBuffer.allocate(buf.limit()); } copy.put(buf); return copy; }