This method implements blocking memcpy

@param dstBuffer
@param srcBuffer
348266
@Override
    public void memcpy(DataBuffer dstBuffer, DataBuffer srcBuffer) {
        this.memoryHandler.memcpy(dstBuffer, srcBuffer);
    }
831603
public void writeBytes(final byte[] bytes, final int off, final int len)
    {
        if (len > remaining())
        {
            writeBytesSlow(bytes, off, len);
            return;
        }

        final Block block = current;
        System.arraycopy(bytes, off, block.data, block.limit, len);
        block.limit += len;
    }
942079
public final void fstp(Mem dst)
  {
    assert(dst.size() == 4 || dst.size() == 8 || dst.size() == 10);
    emitX86(INST_FSTP, dst);
  }
261493
private void tailRecord(byte[] b, int off, int len) throws IOException {
        if(this.position >= this.buffer.length){
            this.ensureDiskStream().write(b, off, len);
            this.position += len;
        } else {
            assert this.buffer != null: "Buffer is null";
            int toCopy = (int)Math.min(this.buffer.length - this.position, len);
            assert b != null: "Passed buffer is null";
            System.arraycopy(b, off, this.buffer, (int)this.position, toCopy);
            this.position += toCopy;
            // TODO verify these are +1 -1 right
            if (toCopy < len) {
                tailRecord(b, off + toCopy, len - toCopy);
            }
        }
    }
70726
public final void fisubr(Mem src)
  {
    assert(src.size() == 2 || src.size() == 4);
    emitX86(INST_FISUBR, src);
  }
868064
@Override
  public void write(byte[] b, int start, int length) throws IOException {
    currentDataSegmentBuffer.write(b, start, length);
    flushIfNeeded();
  }
563341
public boolean sendTCPBytes(ByteBuffer[] srcbuffers, int length)
    {
        boolean success = false;
        try
        {
            ByteBuffer header = createHeader(length);
            ByteBuffer[] buffers = new ByteBuffer[1 + srcbuffers.length];
            buffers[0] = header;
            for (int i = 0; i < srcbuffers.length; i++)
                buffers[i + 1] = srcbuffers[i];
            if (TCPUtils.isLogging())
            {
                long t1 = System.nanoTime();
                long bytesWritten = write(buffers);
                long t2 = System.nanoTime();
                double rate = 1000.0 * 1000.0 * 1000.0 * (double) (bytesWritten) / (1024.0 * (double) (t2 - t1));
                Log(Level.INFO, "Sent " + bytesWritten + " bytes at " + rate + " Kb/s");
            }
            else
            {
                write(buffers);
            }
            success = true;
        }
        catch (Exception e)
        {
            SysLog(Level.SEVERE, "Failed to send TCP bytes: " + e);
            try { channel.close(); } catch (IOException ioe) {}
        }
        return success;
    }
741625
@Override
    protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
        int start = dstIndex;
        SMBUtil.writeInt2(49, dst, dstIndex);
        dst[ dstIndex + 2 ] = this.padding;
        dst[ dstIndex + 3 ] = this.readFlags;
        dstIndex += 4;
        SMBUtil.writeInt4(this.readLength, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt8(this.offset, dst, dstIndex);
        dstIndex += 8;
        System.arraycopy(this.fileId, 0, dst, dstIndex, 16);
        dstIndex += 16;
        SMBUtil.writeInt4(this.minimumCount, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt4(this.channel, dst, dstIndex);
        dstIndex += 4;
        SMBUtil.writeInt4(this.remainingBytes, dst, dstIndex);
        dstIndex += 4;

        // ReadChannelInfo
        SMBUtil.writeInt2(0, dst, dstIndex);
        SMBUtil.writeInt2(0, dst, dstIndex + 2);
        dstIndex += 4;

        // one byte in buffer must be zero
        dst[ dstIndex ] = 0;
        dstIndex += 1;

        return dstIndex - start;
    }
271161
@Override
    public void memcpyAsync(DataBuffer dstBuffer, Pointer srcPointer, long length, long dstOffset) {
        AllocationPoint point = ((BaseCudaDataBuffer) dstBuffer).getAllocationPoint();
        // we update host memory regardless.
        //Pointer dP = new Pointer((point.getAllocationStatus() == AllocationStatus.DEVICE ? point.getPointers().getDevicePointer().address() : point.getPointers().getHostPointer().address()) + dstOffset);
        Pointer dP = new CudaPointer((point.getPointers().getHostPointer().address()) + dstOffset);
        //        Pointer sP = new Pointer(srcPointer.getNativePointer());
        //log.info("Location: " + point.getAllocationStatus());
        //        if (length > 4)
        //log.info("memcpyAsync:  ["+ srcPointer.getNativePointer()+"] -> ["+ dP.getNativePointer()+"], length: [" + length+ "], offset: ["+ dstOffset+"], dstBufferOffset: ["+(dstBuffer.getElementSize() * dstBuffer.offset()) + "/" + dstBuffer.offset() +"]");

        CudaContext tContext = null;

        if (dstBuffer.isConstant()) {

            org.bytedeco.javacpp.Pointer dstPointer =
                            new CudaPointer(point.getPointers().getHostPointer().address() + dstOffset, 0L);
            org.bytedeco.javacpp.Pointer srcPointerJ = new CudaPointer(srcPointer, length);

            //   log.info("JCPP Memcpy: [{}] -> [{}], length: [{}]", srcPointerJ.address(), dstPointer.address(), length);

            val profD = PerformanceTracker.getInstance().helperStartTransaction();

            org.bytedeco.javacpp.Pointer.memcpy(dstPointer, srcPointerJ, length);

            PerformanceTracker.getInstance().helperRegisterTransaction(point.getDeviceId(), profD, point.getNumberOfBytes(), MemcpyDirection.HOST_TO_HOST);


            point.tickHostRead();
        } else {
            //log.info("Memcpy pointers: [{}] -> [{}]", srcPointer.address(),  dP.address());

            CudaContext context = flowController.prepareAction(point);
            tContext = context;

            val prof = PerformanceTracker.getInstance().helperStartTransaction();

            if (nativeOps.memcpyAsync(dP, srcPointer, length, CudaConstants.cudaMemcpyHostToHost,
                            context.getSpecialStream()) == 0)
                throw new IllegalStateException(
                                "MemcpyAsync H2H failed: [" + srcPointer.address() + "] -> [" + dP.address() + "]");

            flowController.commitTransfer(tContext.getSpecialStream());

            PerformanceTracker.getInstance().helperRegisterTransaction(point.getDeviceId(), prof, point.getNumberOfBytes(),MemcpyDirection.HOST_TO_HOST);

            if (point.getAllocationStatus() == AllocationStatus.HOST)
                flowController.registerAction(context, point);
        }

        // if we're copying something into host memory, but we're on device - we need to provide exact copy to device as well
        if (point.getAllocationStatus() == AllocationStatus.DEVICE) {
            // TODO: this sounds wrong, and probably memcpy whould check initial direction, like relocate did before
            Pointer rDP = new CudaPointer(point.getPointers().getDevicePointer().address() + dstOffset);

            if (tContext == null)
                tContext = flowController.prepareAction(point);
            //log.info("MemcpyAsync to device... [{}] -> [{}]", dP.getNativePointer(), rDP.getNativePointer());

            val prof = PerformanceTracker.getInstance().helperStartTransaction();

            if (nativeOps.memcpyAsync(rDP, dP, length, CudaConstants.cudaMemcpyHostToDevice,
                            tContext.getSpecialStream()) == 0)
                throw new IllegalStateException(
                                "MemcpyAsync H2D failed: [" + dP.address() + "] -> [" + rDP.address() + "]");

            flowController.commitTransfer(tContext.getSpecialStream());

            PerformanceTracker.getInstance().helperRegisterTransaction(point.getDeviceId(), prof, point.getNumberOfBytes(),MemcpyDirection.HOST_TO_DEVICE);

            flowController.registerAction(tContext, point);


        }
        point.tickDeviceWrite();
    }
873683
private void writeByteBufferCommonFields(ByteBuffer buf)
  {
    buf.putDouble(lowerLimit);
    buf.putDouble(upperLimit);
    buf.putInt(numBuckets);
    buf.put((byte) outlierHandlingMode.ordinal());

    buf.putLong(count);
    buf.putLong(lowerOutlierCount);
    buf.putLong(upperOutlierCount);
    buf.putLong(missingValueCount);

    buf.putDouble(max);
    buf.putDouble(min);
  }
992037
public static ByteBuffer cloneByteBuffer(ByteBuffer buf) {
    ByteBuffer ret = ByteBuffer.allocate(buf.limit() - buf.position());
    if (buf.hasArray()) {
      ret.put(buf.array(), buf.position(), buf.limit() - buf.position());
    } else {
      // direct buffer
      ret.put(buf);
    }
    ret.flip();
    return ret;
  }
817469
public static void bufferedToInterleaved(DataBufferByte buffer, WritableRaster src, InterleavedF32 dst) {
		byte[] srcData = buffer.getData();

		int srcStride = stride(src);
		int srcOffset = getOffset(src);

		int length = dst.width*dst.numBands;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, dst.height, y -> {
		for (int y = 0; y < dst.height; y++) {
			int indexSrc = srcOffset + y*srcStride;
			int indexDst = dst.startIndex + dst.stride * y;
			int indexDstEnd = indexDst + length;
			while( indexDst < indexDstEnd) {
				dst.data[indexDst++] = srcData[indexSrc++] & 0xFF;
			}
		}
		//CONCURRENT_ABOVE });
	}
262682
private static boolean directByteBufferEquals(ByteBuffer buffa, ByteBuffer buffb)
    {
        if ( buffa == buffb )
        {
            return true;
        }
        
        if ( buffa ==null || buffb == null )
        {
            return false;
        }
        
        buffa.rewind();
        buffb.rewind();
        
        int length = buffa.remaining();
        
        if ( buffb.remaining() != length )
        {
            return false;
        }
        
        for ( int i = 0; i < length; i++ )
        {
            if ( buffa.get() != buffb.get() )
            {
                return false;
            }
        }

        return true;
    }
1080266
public static void copyFromBytes(
			MemorySegment[] segments, int offset,
			byte[] bytes, int bytesOffset, int numBytes) {
		if (segments.length == 1) {
			segments[0].put(offset, bytes, bytesOffset, numBytes);
		} else {
			copyMultiSegmentsFromBytes(segments, offset, bytes, bytesOffset, numBytes);
		}
	}
37016
static void bufferedToPlanar_U8(DataBufferByte buffer , WritableRaster src, Planar<GrayU8> dst) {
		byte[] srcData = buffer.getData();

		int numBands = src.getNumBands();

		int srcStride = stride(src);
		int srcOffset = getOffset(src);

		if(BoofConcurrency.USE_CONCURRENT ) {
			if (numBands == 3) {
				ImplConvertRaster_MT.from_3BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster_MT.from_1BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster_MT.from_4BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		} else {
			if (numBands == 3) {
				ImplConvertRaster.from_3BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster.from_1BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster.from_4BU8_to_PLU8(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		}
	}
366413
public static int writeDeferredSerialization(ByteBuffer mbuf, DeferredSerialization ds) throws IOException
    {
        int written = 0;
        try {
            final int objStartPosition = mbuf.position();
            ds.serialize(mbuf);
            written = mbuf.position() - objStartPosition;
        } finally {
            ds.cancel();
        }
        return written;
    }
500625
static void bufferedToPlanar_F32(DataBufferByte buffer, WritableRaster src, Planar<GrayF32> dst) {
		byte[] srcData = buffer.getData();

		int numBands = src.getNumBands();

		int srcStride = stride(src);
		int srcOffset = getOffset(src);

		if(BoofConcurrency.USE_CONCURRENT ) {
			if (numBands == 3) {
				ImplConvertRaster_MT.from_3BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster_MT.from_1BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster_MT.from_4BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		} else {
			if (numBands == 3) {
				ImplConvertRaster.from_3BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 1) {
				ImplConvertRaster.from_1BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else if (numBands == 4) {
				ImplConvertRaster.from_4BU8_to_PLF32(srcData, srcStride, srcOffset, dst);
			} else {
				throw new RuntimeException("Write more code here.");
			}
		}
	}