zhangstar333 commented on code in PR #56181:
URL: https://github.com/apache/doris/pull/56181#discussion_r2366633095


##########
fe/be-java-extensions/java-common/src/main/java/org/apache/doris/common/jni/utils/OffHeap.java:
##########
@@ -199,6 +199,48 @@ public static long reallocateMemory(long address, long 
oldSize, long newSize) {
         return newMemory;
     }
 
+    /**
+     * Allocate a batch of off-heap memory blocks via single JNI call.
+     * When testing mode is enabled, this falls back to per-block 
allocateMemory wrapper.
+     */
+    public static long[] allocateMemoryBatch(int[] sizes) {
+        if (sizes == null || sizes.length == 0) {
+            return new long[0];
+        }
+        if (IS_TESTING) {
+            long[] addrs = new long[sizes.length];
+            for (int i = 0; i < sizes.length; i++) {
+                addrs[i] = allocateMemory(sizes[i]);
+            }
+            return addrs;
+        } else {
+            long[] addrs = JNINativeMethod.memoryTrackerMallocBatch(sizes);
+            if (addrs == null) {
+                throw new OutOfMemoryError("memoryTrackerMallocBatch failed 
for " + sizes.length + " blocks");
+            }
+            return addrs;
+        }
+    }
+
+    /**
+     * Free a batch of off-heap memory blocks via single JNI call.
+     * When testing mode is enabled, this falls back to per-block freeMemory 
wrapper.
+     */
+    public static void freeMemoryBatch(long[] addrs) {
+        if (addrs == null || addrs.length == 0) {

Review Comment:
   This check is a defensive safeguard to keep, and maybe the overhead is 
trivial compared to a JNI call



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