/** Calls {@code FloatRawIndexer(pointer, { pointer.limit() - pointer.position() }, { 1 })}. */ public FloatRawIndexer(FloatPointer pointer) { this(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
/** Returns {@code create(pointer, { pointer.limit() - pointer.position() }, { 1 }, true)} */ public static FloatIndexer create(FloatPointer pointer) { return create(pointer, new long[] { pointer.limit() - pointer.position() }, ONE_STRIDE); }
/** Constructor to set the {@link #pointer}, {@link #sizes} and {@link #strides}. */ public FloatRawIndexer(FloatPointer pointer, long[] sizes, long[] strides) { super(sizes, strides); this.pointer = pointer; base = pointer.address() + pointer.position() * VALUE_BYTES; size = pointer.limit() - pointer.position(); }
/** * @param floatPointer * @param length * @return */ @Override public DataBuffer create(FloatPointer floatPointer, long length) { floatPointer.capacity(length); floatPointer.limit(length); floatPointer.position(0); return new FloatBuffer(floatPointer, FloatIndexer.create(floatPointer), length); }
/** * Creates a float indexer to access efficiently the data of a pointer. * * @param pointer data to access via a buffer or to copy to an array * @param direct {@code true} to use a direct buffer, see {@link Indexer} for details * @return the new float indexer backed by the raw memory interface, a buffer, or an array */ public static FloatIndexer create(final FloatPointer pointer, long[] sizes, long[] strides, boolean direct) { if (direct) { return Raw.getInstance() != null ? new FloatRawIndexer(pointer, sizes, strides) : new FloatBufferIndexer(pointer.asBuffer(), sizes, strides); } else { final long position = pointer.position(); float[] array = new float[(int)Math.min(pointer.limit() - position, Integer.MAX_VALUE)]; pointer.get(array); return new FloatArrayIndexer(array, sizes, strides) { @Override public void release() { pointer.position(position).put(array); super.release(); } }; } }
/** * 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(float[]) */ public FloatPointer(FloatBuffer buffer) { super(buffer); if (buffer != null && !buffer.isDirect() && buffer.hasArray()) { float[] array = buffer.array(); allocateArray(array.length - buffer.arrayOffset()); put(array, buffer.arrayOffset(), array.length - buffer.arrayOffset()); position(buffer.position()); limit(buffer.limit()); } } /**