dropByteBuffer -> releaseByteBuffer

This commit is contained in:
2024-08-24 15:25:03 +02:00
parent b457e8afd4
commit 09e1c063bb
3 changed files with 5 additions and 4 deletions

View File

@@ -16,7 +16,7 @@ class DhfsSupportNative {
static native long allocateUninitializedByteBuffer(ByteBuffer[] bb, int size);
static native void dropByteBuffer(long token);
static native void releaseByteBuffer(long token);
private static native int getPageSizeInternal();
}

View File

@@ -13,7 +13,7 @@ public class UninitializedByteBuffer {
var bb = new ByteBuffer[1];
long token = DhfsSupportNative.allocateUninitializedByteBuffer(bb, size);
var ret = bb[0];
CLEANER.register(ret, () -> DhfsSupportNative.dropByteBuffer(token));
CLEANER.register(ret, () -> DhfsSupportNative.releaseByteBuffer(token));
return ret;
}
}

View File

@@ -26,7 +26,8 @@ JNIEXPORT jlong JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_alloc
if (checked_size < MemoryHelpers::get_page_size())
buf = malloc(checked_size);
else
buf = std::aligned_alloc(MemoryHelpers::get_page_size(), align_up(checked_size, MemoryHelpers::get_page_size()));
buf = std::aligned_alloc(MemoryHelpers::get_page_size(),
align_up(checked_size, MemoryHelpers::get_page_size()));
if (buf == nullptr) {
env->ThrowNew(env->FindClass("java/lang/OutOfMemoryError"), "Buffer memory allocation failed");
@@ -39,7 +40,7 @@ JNIEXPORT jlong JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_alloc
return token;
}
JNIEXPORT void JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_dropByteBuffer
JNIEXPORT void JNICALL Java_com_usatiuk_dhfs_supportlib_DhfsSupportNative_releaseByteBuffer
(JNIEnv* env, jclass klass, jlong token) {
const auto addr = checked_cast<uintptr_t>(token);