Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19222#discussion_r147573017
  
    --- Diff: 
common/unsafe/src/main/java/org/apache/spark/unsafe/memory/UnsafeMemoryAllocator.java
 ---
    @@ -19,28 +19,48 @@
     
     import org.apache.spark.unsafe.Platform;
     
    +import java.lang.reflect.InvocationTargetException;
    +import java.lang.reflect.Method;
    +import java.nio.ByteBuffer;
    +
    +import sun.nio.ch.DirectBuffer;
    +
     /**
      * A simple {@link MemoryAllocator} that uses {@code Unsafe} to allocate 
off-heap memory.
      */
     public class UnsafeMemoryAllocator implements MemoryAllocator {
     
       @Override
    -  public MemoryBlock allocate(long size) throws OutOfMemoryError {
    -    long address = Platform.allocateMemory(size);
    -    MemoryBlock memory = new MemoryBlock(null, address, size);
    -    if (MemoryAllocator.MEMORY_DEBUG_FILL_ENABLED) {
    -      memory.fill(MemoryAllocator.MEMORY_DEBUG_FILL_CLEAN_VALUE);
    +  public OffHeapMemoryBlock allocate(long size) throws OutOfMemoryError {
    +    Object buffer = ByteBuffer.allocateDirect((int)size);
    --- End diff --
    
    I knew that to use `Platform.allocateMemory` is [current 
design](http://downloads.typesafe.com/website/presentations/ScalaDaysSF2015/T4_Xin_Performance_Optimization.pdf#page=26).
 I will revert this change.
    
    If we want to use `ByteBuffer.allocateDirect`, it would be good to submit a 
separate PR.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to