@Override
    public DataBuffer reallocate(long length) {

        Pointer oldPointer = pointer;
        if (isAttached()) {
            long capacity = length * getElementSize();
            switch (dataType()) {
                case DOUBLE:
                    pointer = getParentWorkspace().alloc(capacity, Type.DOUBLE, false).asDoublePointer();
                    indexer = DoubleIndexer.create((DoublePointer) pointer);
                    break;
                case FLOAT:
                    pointer = getParentWorkspace().alloc(capacity, Type.FLOAT, false).asFloatPointer();
                    indexer = FloatIndexer.create((FloatPointer) pointer);
                    break;
                case INT:
                    pointer = getParentWorkspace().alloc(capacity, Type.INT, false).asIntPointer();
                    indexer = IntIndexer.create((IntPointer) pointer);

                    break;
            }

            workspaceGenerationId = getParentWorkspace().getGenerationId();
        } else {
            switch (dataType()) {
                case INT:
                    pointer = new IntPointer(length);
                    indexer = IntIndexer.create((IntPointer) pointer);
                    break;
                case DOUBLE:
                    pointer = new DoublePointer(length);
                    indexer = DoubleIndexer.create((DoublePointer) pointer);
                    break;
                case FLOAT:
                    pointer = new FloatPointer(length);
                    indexer = FloatIndexer.create((FloatPointer) pointer);
                    break;
            }
        }

        Pointer.memcpy(pointer, oldPointer, this.length() * getElementSize());
        //this.underlyingLength = length;
        return this;
    }
@Override
    public DataBuffer reallocate(long length) {

        Pointer oldPointer = pointer;
        if (isAttached()) {
            long capacity = length * getElementSize();
            switch (dataType()) {
                case DOUBLE:
                    pointer = getParentWorkspace().alloc(capacity, Type.DOUBLE, false).asDoublePointer();
                    indexer = DoubleIndexer.create((DoublePointer) pointer);
                    break;
                case FLOAT:
                    pointer = getParentWorkspace().alloc(capacity, Type.FLOAT, false).asFloatPointer();
                    indexer = FloatIndexer.create((FloatPointer) pointer);
                    break;
                case INT:
                    pointer = getParentWorkspace().alloc(capacity, Type.INT, false).asIntPointer();
                    indexer = IntIndexer.create((IntPointer) pointer);

                    break;
            }

            workspaceGenerationId = getParentWorkspace().getGenerationId();
        } else {
            switch (dataType()) {
                case INT:
                    pointer = new IntPointer(length);
                    indexer = IntIndexer.create((IntPointer) pointer);
                    break;
                case DOUBLE:
                    pointer = new DoublePointer(length);
                    indexer = DoubleIndexer.create((DoublePointer) pointer);
                    break;
                case FLOAT:
                    pointer = new FloatPointer(length);
                    indexer = FloatIndexer.create((FloatPointer) pointer);
                    break;
            }
        }

        Pointer.memcpy(pointer, oldPointer, this.length() * getElementSize());
        
        return this;
    }
@ Override public DataBuffer reallocate ( long length ) { Pointer oldPointer = pointer ; if ( isAttached ( ) ) { long capacity = length * getElementSize ( ) ; switch ( dataType ( ) ) { case DOUBLE : pointer = getParentWorkspace ( ) . alloc ( capacity , Type . DOUBLE , false ) . asDoublePointer ( ) ; indexer = DoubleIndexer . create ( ( DoublePointer ) pointer ) ; break ; case FLOAT : pointer = getParentWorkspace ( ) . alloc ( capacity , Type . FLOAT , false ) . asFloatPointer ( ) ; indexer = FloatIndexer . create ( ( FloatPointer ) pointer ) ; break ; case INT : pointer = getParentWorkspace ( ) . alloc ( capacity , Type . INT , false ) . asIntPointer ( ) ; indexer = IntIndexer . create ( ( IntPointer ) pointer ) ; break ; } workspaceGenerationId = getParentWorkspace ( ) . getGenerationId ( ) ; } else { switch ( dataType ( ) ) { case INT : pointer = new IntPointer ( length ) ; indexer = IntIndexer . create ( ( IntPointer ) pointer ) ; break ; case DOUBLE : pointer = new DoublePointer ( length ) ; indexer = DoubleIndexer . create ( ( DoublePointer ) pointer ) ; break ; case FLOAT : pointer = new FloatPointer ( length ) ; indexer = FloatIndexer . create ( ( FloatPointer ) pointer ) ; break ; } } Pointer . memcpy ( pointer , oldPointer , this . length ( ) * getElementSize ( ) ) ; //this.underlyingLength = length; return this ; }
Reallocate the native memory of the buffer
@param length the new length of the buffer
@return this databuffer
Reallocate the native memory of the buffer