Example usage for org.apache.spark.unsafe Platform copyMemory

List of usage examples for org.apache.spark.unsafe Platform copyMemory

Introduction

In this page you can find the example usage for org.apache.spark.unsafe Platform copyMemory.

Prototype

public static void copyMemory(Object src, long srcOffset, Object dst, long dstOffset, long length) 

Source Link

Usage

From source file:com.splicemachine.db.iapi.types.SQLArray.java

License:Apache License

/**
 *
 * Write into a Project Tungsten format (UnsafeRow).  This calls the
 * reference's write method./*from ww  w  . j a  v a2 s  .  c  om*/
 *
 *
 * @param unsafeRowWriter
 * @param ordinal
 * @throws StandardException
  */
public void write(UnsafeRowWriter unsafeRowWriter, int ordinal) throws StandardException {
    if (isNull()) {
        unsafeRowWriter.setNullAt(ordinal);
    } else {
        UnsafeArrayWriter unsafeArrayWriter = new UnsafeArrayWriter();
        BufferHolder bh = new BufferHolder(new UnsafeRow(value.length));
        unsafeArrayWriter.initialize(bh, value.length, 8); // 4 bytes for int?
        for (int i = 0; i < value.length; i++) {
            if (value[i] == null || value[i].isNull()) {
                unsafeArrayWriter.setNull(i);
            } else {
                value[i].writeArray(unsafeArrayWriter, i);
            }
        }
        long currentOffset = unsafeRowWriter.holder().cursor;
        unsafeRowWriter.setOffsetAndSize(ordinal, bh.cursor - 16);
        unsafeRowWriter.holder().grow(bh.cursor - 16);
        Platform.copyMemory(bh.buffer, 16, unsafeRowWriter.holder().buffer, currentOffset, bh.cursor - 16);
    }
}

From source file:edu.ucla.cs.wis.bigdatalog.spark.storage.map.UnsafeFixedWidthMonotonicAggregationMap.java

License:Apache License

private void write(byte[] buffer, MemoryLocation addr, int length, ObjectOutput out)
        throws java.io.IOException {
    if (buffer.length < length)
        buffer = new byte[length];

    Platform.copyMemory(addr.getBaseObject(), addr.getBaseOffset(), buffer, Platform.BYTE_ARRAY_OFFSET, length);
    out.write(buffer, 0, length);//from  w  ww  .j a  v a 2 s  . c  o  m
}