1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.buffer.api.pool;
17
18 import io.netty5.buffer.api.AllocationType;
19 import io.netty5.buffer.api.Buffer;
20 import io.netty5.buffer.api.Drop;
21 import io.netty5.buffer.api.MemoryManager;
22 import io.netty5.buffer.api.internal.DropCaptor;
23
24 import static io.netty5.buffer.api.internal.Statics.standardDrop;
25
26 @SuppressWarnings("unchecked")
27 class UnpooledUntetheredMemory implements UntetheredMemory {
28 private final MemoryManager manager;
29 private final Buffer buffer;
30 private final DropCaptor<Buffer> dropCaptor;
31
32 UnpooledUntetheredMemory(PooledBufferAllocator allocator, MemoryManager manager,
33 AllocationType allocationType, int size) {
34 this.manager = manager;
35 dropCaptor = new DropCaptor<>();
36 buffer = manager.allocateShared(allocator.getPooledAllocatorControl(), size, dropCaptor, allocationType);
37 }
38
39 @Override
40 public <Memory> Memory memory() {
41 return (Memory) manager.unwrapRecoverableMemory(buffer);
42 }
43
44 @Override
45 public <BufferType extends Buffer> Drop<BufferType> drop() {
46 return (Drop<BufferType>) standardDrop(manager).apply(dropCaptor.getDrop());
47 }
48 }