/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(short[]) */ public ShortPointer(ShortBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { short[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of shorts to fill * @return the buffer instance */ public static ShortBuffer fill(ShortBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), (short) value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put((short)value); } } return buffer; }
/** * Take a certain number of shorts from the buffer and return them in an array. * * @param buffer the buffer to read * @param cnt the number of shorts to take * @return the shorts */ public static short[] take(ShortBuffer buffer, int cnt) { if (cnt < 0) { throw msg.parameterOutOfRange("cnt"); } if (buffer.hasArray()) { final int pos = buffer.position(); final int lim = buffer.limit(); if (lim - pos < cnt) { throw new BufferUnderflowException(); } final short[] array = buffer.array(); final int offset = buffer.arrayOffset(); buffer.position(pos + cnt); final int start = offset + pos; return Arrays.copyOfRange(array, start, start + cnt); } final short[] shorts = new short[cnt]; buffer.get(shorts); return shorts; }
/** * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers * backed with an array, allocates enough memory for the array and copies it. * * @param buffer the Buffer to reference or copy * @see #put(short[]) */ public ShortPointer(ShortBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { short[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**
return (SIZEOF_INT * (((IntBuffer) buf).arrayOffset() + pos)); } else if (buf instanceof ShortBuffer) { return (SIZEOF_SHORT * (((ShortBuffer) buf).arrayOffset() + pos)); } else if (buf instanceof DoubleBuffer) { return (SIZEOF_DOUBLE * (((DoubleBuffer) buf).arrayOffset() + pos));
/** * Fill a buffer with a repeated value. * * @param buffer the buffer to fill * @param value the value to fill * @param count the number of shorts to fill * @return the buffer instance */ public static ShortBuffer fill(ShortBuffer buffer, int value, int count) { if (count > buffer.remaining()) { throw msg.bufferUnderflow(); } if (buffer.hasArray()) { final int offs = buffer.arrayOffset(); Arrays.fill(buffer.array(), offs + buffer.position(), offs + buffer.limit(), (short) value); skip(buffer, count); } else { for (int i = count; i > 0; i--) { buffer.put((short)value); } } return buffer; }
/** * Take a certain number of shorts from the buffer and return them in an array. * * @param buffer the buffer to read * @param cnt the number of shorts to take * @return the shorts */ public static short[] take(ShortBuffer buffer, int cnt) { if (cnt < 0) { throw msg.parameterOutOfRange("cnt"); } if (buffer.hasArray()) { final int pos = buffer.position(); final int lim = buffer.limit(); if (lim - pos < cnt) { throw new BufferUnderflowException(); } final short[] array = buffer.array(); final int offset = buffer.arrayOffset(); buffer.position(pos + cnt); final int start = offset + pos; return Arrays.copyOfRange(array, start, start + cnt); } final short[] shorts = new short[cnt]; buffer.get(shorts); return shorts; }
int offset = buffer.arrayOffset(); int length = array.length - offset; Pointer<Short> ptr = allocateShorts(length);
setShortsAtOffset(byteOffset, values.array(), (int)(values.arrayOffset() + valuesOffset), (int)length);
int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.cl_short);
int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.cl_short);
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(ShortBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.SHORT); buffer.position(oldPosition); } else if (buffer.hasArray()) { ShortBuffer t = ShortBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.SHORT); } return result; }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(ShortBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.SHORT); buffer.position(oldPosition); } else if (buffer.hasArray()) { ShortBuffer t = ShortBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.SHORT); } return result; }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(ShortBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.SHORT); buffer.position(oldPosition); } else if (buffer.hasArray()) { ShortBuffer t = ShortBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.SHORT); } return result; }
/** * Creates a new Pointer to the given buffer, taking into * account the position and array offset of the given buffer. * The buffer is assumed to be non-<code>null</code>, and * be either direct or have a backing array. * * @param buffer The buffer * @return The pointer */ private static Pointer computePointer(ShortBuffer buffer) { Pointer result = null; if (buffer.isDirect()) { int oldPosition = buffer.position(); buffer.position(0); result = Pointer.to(buffer.slice()).withByteOffset( oldPosition * Sizeof.SHORT); buffer.position(oldPosition); } else if (buffer.hasArray()) { ShortBuffer t = ShortBuffer.wrap(buffer.array()); int elementOffset = buffer.position() + buffer.arrayOffset(); result = Pointer.to(t).withByteOffset( elementOffset * Sizeof.SHORT); } return result; }