chaokunyang commented on code in PR #2457:
URL: https://github.com/apache/fory/pull/2457#discussion_r2269398069


##########
java/fory-core/src/main/java/org/apache/fory/memory/MemoryBuffer.java:
##########
@@ -1249,6 +1247,13 @@ private void growBuffer(int length) {
         length < BUFFER_GROW_STEP_THRESHOLD
             ? length << 2
             : (int) Math.min(length * 1.5d, Integer.MAX_VALUE - 8);
+    if (heapMemory == null) {
+      ByteBuffer bb = ByteBuffer.allocateDirect(newSize);

Review Comment:
   The implememtation may use such allocator, but fory could just define an 
interface, and let users to implement such `ByteBufferAllocator`. 
   
   Another thing we need to figure out is memory deallocation of such buffers. 
Since we allocate memory from a `BufferAllocator`, when this `MemoryBuffer` is 
not used, we should return the buffer back to the pool. This is the tricky 
thing to do. Even for `java.nio.ByteBuffer`, this is not tackled well. 
`ByteBuffer` use soft/weak reference to trigger callback when there are no 
reference to `ByteBuffer`. But it's not predictable, this is why 
PooledByteBufAllocator use explict release API `ByteBuf#release`. If we add 
allocator, we should also add `release` method to `MemoryBuffer`



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to