public static final void copy(final Memory source,final long srcOffsetBytes,final Memory destination,final long dstOffsetBytes,final long lengthBytes){
  assertBounds(srcOffsetBytes,lengthBytes,source.getCapacity());
  assertBounds(dstOffsetBytes,lengthBytes,destination.getCapacity());
  if (destination.isReadOnly()) {
    throw new ReadOnlyMemoryException();
  }
  long srcAdd=source.getCumulativeOffset(srcOffsetBytes);
  long dstAdd=destination.getCumulativeOffset(dstOffsetBytes);
  Object srcParent=(source.isDirect()) ? null : source.getNativeMemory().memArray_;
  Object dstParent=(destination.isDirect()) ? null : destination.getNativeMemory().memArray_;
  long lenBytes=lengthBytes;
  while (lenBytes > 0) {
    long chunkBytes=(lenBytes > UNSAFE_COPY_THRESHOLD) ? UNSAFE_COPY_THRESHOLD : lenBytes;
    unsafe.copyMemory(srcParent,srcAdd,dstParent,dstAdd,lenBytes);
    lenBytes-=chunkBytes;
    srcAdd+=chunkBytes;
    dstAdd+=chunkBytes;
  }
}

public static final void copy ( final Memory source , final long srcOffsetBytes , final Memory destination , final long dstOffsetBytes , final long lengthBytes ) { assertBounds ( srcOffsetBytes , lengthBytes , source . getCapacity ( ) ) ; assertBounds ( dstOffsetBytes , lengthBytes , destination . getCapacity ( ) ) ; if ( destination . isReadOnly ( ) ) { throw new ReadOnlyMemoryException ( ) ; } long srcAdd = source . getCumulativeOffset ( srcOffsetBytes ) ; long dstAdd = destination . getCumulativeOffset ( dstOffsetBytes ) ; Object srcParent = ( source . isDirect ( ) ) ? null : source . getNativeMemory ( ) . memArray_ ; Object dstParent = ( destination . isDirect ( ) ) ? null : destination . getNativeMemory ( ) . memArray_ ; long lenBytes = lengthBytes ; while ( lenBytes > 0 ) { long chunkBytes = ( lenBytes > UNSAFE_COPY_THRESHOLD ) ? UNSAFE_COPY_THRESHOLD : lenBytes ; unsafe . copyMemory ( srcParent , srcAdd , dstParent , dstAdd , lenBytes ) ; lenBytes -= chunkBytes ; srcAdd += chunkBytes ; dstAdd += chunkBytes ; } }
copies bytes from a source memory to the destination memory . if the source and destination are the same memory use the single memory copy method . nonetheless , if the source and destination memories are derived from the same underlying base memory , the source and the destination regions should not overlap within the base memory region . this is difficult to check at run time , so be warned that this overlap could cause unpredictable results .
