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


##########
be/src/util/jni_native_method.cpp:
##########
@@ -39,4 +35,75 @@ void JavaNativeMethods::memoryFree(JNIEnv* env, jclass 
clazz, jlong address) {
     free(reinterpret_cast<void*>(address));
 }
 
+jlongArray JavaNativeMethods::memoryMallocBatch(JNIEnv* env, jclass clazz, 
jintArray sizes) {
+    DCHECK(sizes != nullptr);
+    jsize n = env->GetArrayLength(sizes);
+    DCHECK(n > 0);
+    jint* elems = env->GetIntArrayElements(sizes, nullptr);
+    if (elems == nullptr) {
+        return nullptr;
+    }
+    DEFER({
+        if (elems != nullptr) {
+            env->ReleaseIntArrayElements(sizes, elems, JNI_ABORT);
+        }
+    });
+
+    jlongArray result = env->NewLongArray(n);
+    if (result == nullptr) {
+        return nullptr;
+    }
+
+    std::vector<void*> allocated;
+    allocated.reserve(n);
+
+    // sizes are validated on Java side: n > 0 and each size > 0
+    bool failed = false;
+    for (jsize i = 0; i < n; ++i) {
+        auto sz = static_cast<size_t>(elems[i]);
+        void* p = malloc(sz);
+        if (p == nullptr) {
+            failed = true;

Review Comment:
   Use `try-catch` to process



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