2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org
.apache
.arrow
.dataset
.jni
;
21 * C++ memory pool(arrow::MemoryPool)'s Java mapped instance.
23 public class NativeMemoryPool
implements AutoCloseable
{
24 private final long nativeInstanceId
;
27 JniLoader
.get().ensureLoaded();
30 private NativeMemoryPool(long nativeInstanceId
) {
31 this.nativeInstanceId
= nativeInstanceId
;
35 * Get the default memory pool. This will return arrow::default_memory_pool() directly.
37 public static NativeMemoryPool
getDefault() {
38 return new NativeMemoryPool(getDefaultMemoryPool());
42 * Create a listenable memory pool (see also: arrow::ReservationListenableMemoryPool) with
43 * a specific listener. All buffers created from the memory pool should take enough reservation
44 * from the listener in advance.
46 public static NativeMemoryPool
createListenable(ReservationListener listener
) {
47 return new NativeMemoryPool(createListenableMemoryPool(listener
));
51 * Return native instance ID of this memory pool.
53 public long getNativeInstanceId() {
54 return nativeInstanceId
;
58 * Get current allocated bytes.
60 public long getBytesAllocated() {
61 return bytesAllocated(nativeInstanceId
);
65 public void close() throws Exception
{
66 releaseMemoryPool(nativeInstanceId
);
69 private static native long getDefaultMemoryPool();
71 private static native long createListenableMemoryPool(ReservationListener listener
);
73 private static native void releaseMemoryPool(long id
);
75 private static native long bytesAllocated(long id
);