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


##########
be/src/util/jni_native_method.cpp:
##########
@@ -39,4 +33,81 @@ void JavaNativeMethods::memoryFree(JNIEnv* env, jclass 
clazz, jlong address) {
     free(reinterpret_cast<void*>(address));
 }
 
+jlongArray JavaNativeMethods::memoryMallocBatch(JNIEnv* env, jclass clazz, 
jintArray sizes) {
+    if (sizes == nullptr) {
+        return env->NewLongArray(0);
+    }
+    jsize n = env->GetArrayLength(sizes);
+    if (n <= 0) {
+        return env->NewLongArray(0);
+    }
+
+    jint* elems = env->GetIntArrayElements(sizes, nullptr);
+    if (elems == nullptr) {
+        return nullptr;
+    }
+
+    jlongArray result = env->NewLongArray(n);
+    if (result == nullptr) {
+        env->ReleaseIntArrayElements(sizes, elems, JNI_ABORT);
+        return nullptr;
+    }
+
+    std::vector<void*> allocated;
+    allocated.reserve(n);
+
+    bool failed = false;
+    for (jsize i = 0; i < n; ++i) {
+        jint sz = elems[i];
+        if (sz <= 0) {
+            allocated.push_back(nullptr);
+            continue;
+        }
+        void* p = malloc(static_cast<size_t>(sz));
+        if (p == nullptr) {
+            failed = true;
+            break;
+        }
+        allocated.push_back(p);
+    }
+
+    if (failed) {
+        for (void* p : allocated) {
+            if (p != nullptr) {
+                free(p);
+            }
+        }
+        env->ReleaseIntArrayElements(sizes, elems, JNI_ABORT);
+        return nullptr;
+    }
+
+    std::vector<jlong> addrs(n);

Review Comment:
   why here direct use result the set?



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