Files
KLALB/src/org/kne/cloud/network/ByteBufferAllocator.java
T
2026-07-07 00:22:32 +08:00

57 lines
1.6 KiB
Java

package org.kne.cloud.network;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentAllocator;
import java.lang.ref.Cleaner;
import java.lang.ref.PhantomReference;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import org.kne.debug.TimeDebugger;
import org.kne.membandboost.MembandBoost;
public class ByteBufferAllocator {
public ByteBufferAllocator(boolean isDirect) {
}
public ByteBuffer allocate(int capacity) {
//if(capacity<1024)
return allocateHeap(capacity);
// return allocateNative(capacity);
}
//private Arena ar=BufferedArena.ofBuffered();
//private Arena ara=Arena.ofAuto();
public ByteBuffer allocateNative(int capacity) {
//return ((jdk.internal.foreign.ArenaImpl)ara).allocateNoInit(capacity,1).asByteBuffer();
ByteBuffer buf=Arena.ofAuto().allocate(capacity).asByteBuffer();
if(buf.capacity()!=capacity)
throw new InternalError();
return buf;
}
public static ByteBuffer allocateHeap(int capacity) {
/*if(capacity<=2048) {
return MembandBoost.allocateUninitializedHeapBufferBlocked(capacity);
}else {*/
return MembandBoost.allocateUninitializedHeapBuffer(capacity);
//}
}
}