xintongsong commented on a change in pull request #9747: [FLINK-13985] Use 
unsafe memory for managed memory
URL: https://github.com/apache/flink/pull/9747#discussion_r328422844
 
 

 ##########
 File path: 
flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -86,16 +86,16 @@ public static MemorySegment 
allocateUnpooledOffHeapMemory(int size) {
        }
 
        /**
-        * Allocates some unpooled off-heap memory and creates a new memory 
segment that
-        * represents that memory.
+        * Allocates an unpooled off-heap memory and creates a new memory 
segment to represent that memory.
         *
         * @param size The size of the off-heap memory segment to allocate.
         * @param owner The owner to associate with the off-heap memory segment.
         * @return A new memory segment, backed by unpooled off-heap memory.
         */
        public static MemorySegment allocateUnpooledOffHeapMemory(int size, 
Object owner) {
-               ByteBuffer memory = ByteBuffer.allocateDirect(size);
-               return new HybridMemorySegment(memory, owner);
+               long address = MemoryUtils.allocateUnsafe(size);
+               ByteBuffer offHeapBuffer = 
MemoryUtils.wrapUnsafeMemoryWithByteBuffer(address, size);
+               return new HybridMemorySegment(offHeapBuffer, owner, 
MemoryUtils.createMemoryGcCleaner(offHeapBuffer, address));
 
 Review comment:
   Both safe and unsafe off-heap memory can be wrapped in 
`HybridMemorySegment`. The only difference is that the unsafe ones have 
non-null cleaners.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to