forked from KNEMC/KLALB
KLALB V3.6.0 写了一半
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package org.kne.cloud.network;
|
||||
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.lang.foreign.MemorySegment.Scope;
|
||||
import java.lang.ref.PhantomReference;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
public class HeapBufferedArena implements Arena{
|
||||
private static long blockSize=32768L;
|
||||
private MemorySegment segment;
|
||||
private long pos=0;
|
||||
|
||||
|
||||
|
||||
|
||||
public static void setBlockSize(long blockSizex) {
|
||||
blockSize = blockSizex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void allocateNew(long blockSize2) {
|
||||
segment=MemorySegment.ofArray(ByteBufferAllocator.allocateUninitializedArray((int) blockSize2));
|
||||
pos=0;
|
||||
}
|
||||
|
||||
|
||||
public HeapBufferedArena() {
|
||||
super();
|
||||
allocateNew(blockSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemorySegment allocate(long byteSize, long byteAlignment) {
|
||||
if(byteSize>blockSize)
|
||||
return MemorySegment.ofArray(ByteBufferAllocator.allocateUninitializedArray((int) byteSize));
|
||||
do{
|
||||
long newpos=pos+byteSize;
|
||||
if(newpos>blockSize) {
|
||||
allocateNew(blockSize);
|
||||
}else {
|
||||
MemorySegment ms=segment.asSlice(pos, byteSize);
|
||||
pos=newpos;
|
||||
return ms;
|
||||
}
|
||||
}while(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scope scope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
public static HeapBufferedArena ofBuffered() {
|
||||
return new HeapBufferedArena();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user