zhztheplayer commented on a change in pull request #10108:
URL: https://github.com/apache/arrow/pull/10108#discussion_r623221415



##########
File path: cpp/src/jni/dataset/jni_util.cc
##########
@@ -117,26 +118,48 @@ class ReservationListenableMemoryPool::Impl {
   std::shared_ptr<ReservationListener> get_listener() { return listener_; }
 
  private:
-  arrow::MemoryPool* pool_;
+  MemoryPool* pool_;
   std::shared_ptr<ReservationListener> listener_;
   int64_t block_size_;
   int64_t blocks_reserved_;
   int64_t bytes_reserved_;
   std::mutex mutex_;
 };
 
+/// \brief Buffer implementation that binds to a
+/// Java buffer reference. Java buffer's release
+/// method will be called once when being destructed.
+class JavaAllocatedBuffer : public Buffer {
+ public:
+  JavaAllocatedBuffer(JNIEnv* env, jobject cleaner_ref, jmethodID 
cleaner_method_ref,
+                      uint8_t* buffer, int32_t len)
+      : Buffer(buffer, len),
+        env_(env),
+        cleaner_ref_(cleaner_ref),
+        cleaner_method_ref_(cleaner_method_ref) {}
+
+  ~JavaAllocatedBuffer() override {
+    env_->CallVoidMethod(cleaner_ref_, cleaner_method_ref_);
+    env_->DeleteGlobalRef(cleaner_ref_);
+  }
+
+ private:
+  JNIEnv* env_;
+  jobject cleaner_ref_;
+  jmethodID cleaner_method_ref_;
+};
+
 ReservationListenableMemoryPool::ReservationListenableMemoryPool(
     MemoryPool* pool, std::shared_ptr<ReservationListener> listener, int64_t 
block_size) {
   impl_.reset(new Impl(pool, listener, block_size));
 }
 
-arrow::Status ReservationListenableMemoryPool::Allocate(int64_t size, 
uint8_t** out) {
+Status ReservationListenableMemoryPool::Allocate(int64_t size, uint8_t** out) {

Review comment:
       Thanks for the suggestion.




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


Reply via email to