- java.lang.Object
-
- io.netty5.buffer.api.bytebuffer.ByteBufferMemoryManager
-
- All Implemented Interfaces:
MemoryManager
public final class ByteBufferMemoryManager extends Object implements MemoryManager
This memory manager produces and managesBuffer
instances that are backed by NIOByteBuffer
instances.Memory managers are normally not used directly. Instead, you likely want to use the
DefaultBufferAllocators
, or the static methods onBufferAllocator
.
-
-
Constructor Summary
Constructors Constructor Description ByteBufferMemoryManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Buffer
allocateConstChild(Buffer readOnlyConstParent)
Allocates a constant buffer based on the given parent.Buffer
allocateShared(AllocatorControl allocatorControl, long size, Function<Drop<Buffer>,Drop<Buffer>> dropDecorator, AllocationType allocationType)
Allocates a shared buffer.void
clearMemory(Object memory)
Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.String
implementationName()
Get the name for this implementation, which can be used for finding this particular implementation via theMemoryManager.lookupImplementation(String)
method.Buffer
recoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop<Buffer> drop)
Recover the memory from a priorMemoryManager.unwrapRecoverableMemory(Buffer)
call, and wrap it in aBuffer
instance.Object
sliceMemory(Object memory, int offset, int length)
Produces a slice of the given internal memory representation object.Object
unwrapRecoverableMemory(Buffer buf)
Create an object that represents the internal memory of the given buffer.
-
-
-
Method Detail
-
allocateShared
public Buffer allocateShared(AllocatorControl allocatorControl, long size, Function<Drop<Buffer>,Drop<Buffer>> dropDecorator, AllocationType allocationType)
Description copied from interface:MemoryManager
Allocates a shared buffer. "Shared" is the normal type of buffer, and means the buffer permit concurrent access from multiple threads, within the limited thread-safety guarantees of theBuffer
interface.- Specified by:
allocateShared
in interfaceMemoryManager
- Parameters:
allocatorControl
- Call-back interface for controlling the allocator that requested the allocation of this buffer.size
- The size of the buffer to allocate. This size is assumed to be valid for the implementation.dropDecorator
- A function to decorate the memory managersDrop
instance. TheDrop
instance returned by this function will be used when the buffer is closed.allocationType
- The type of allocation to perform. Typically, one of the StandardAllocationTypes.- Returns:
- A
Buffer
instance with the given configuration.
-
allocateConstChild
public Buffer allocateConstChild(Buffer readOnlyConstParent)
Description copied from interface:MemoryManager
Allocates a constant buffer based on the given parent. A "constant" buffer is conceptually similar to a read-only buffer, but the implementation may share the underlying memory across multiple buffer instance - something that is normally not allowed by the API. This allows efficient implementation of theBufferAllocator.constBufferSupplier(byte[])
method.Note: The const-parent buffer must be allocated by this memory manager.
- Specified by:
allocateConstChild
in interfaceMemoryManager
- Parameters:
readOnlyConstParent
- The read-only parent buffer for which a const buffer should be created. The parent buffer is allocated in the usual way, withMemoryManager.allocateShared(AllocatorControl, long, Function, AllocationType)
, initialised with contents, and then made read-only.- Returns:
- A const buffer with the same size, contents, and read-only state of the given parent buffer.
-
unwrapRecoverableMemory
public Object unwrapRecoverableMemory(Buffer buf)
Description copied from interface:MemoryManager
Create an object that represents the internal memory of the given buffer.- Specified by:
unwrapRecoverableMemory
in interfaceMemoryManager
- Parameters:
buf
- The buffer to unwrap.- Returns:
- The internal memory of the given buffer, as an opaque object.
-
recoverMemory
public Buffer recoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop<Buffer> drop)
Description copied from interface:MemoryManager
Recover the memory from a priorMemoryManager.unwrapRecoverableMemory(Buffer)
call, and wrap it in aBuffer
instance.- Specified by:
recoverMemory
in interfaceMemoryManager
- Parameters:
allocatorControl
- The allocator control to attach to the buffer.recoverableMemory
- The opaque memory to use for the buffer.drop
- TheDrop
instance to use when the buffer is closed.- Returns:
- A
Buffer
instance backed by the given recovered memory.
-
sliceMemory
public Object sliceMemory(Object memory, int offset, int length)
Description copied from interface:MemoryManager
Produces a slice of the given internal memory representation object.- Specified by:
sliceMemory
in interfaceMemoryManager
- Parameters:
memory
- The opaque memory to slice.offset
- The offset into the memory to slice from.length
- The length of the slice.- Returns:
- A new opaque memory instance that represents the given slice of the original.
-
clearMemory
public void clearMemory(Object memory)
Description copied from interface:MemoryManager
Overwrite the given recoverable memory object with zeroes, erasing all data that it contains.This is used by the
SensitiveBufferAllocator
to erase data on deallocation.- Specified by:
clearMemory
in interfaceMemoryManager
- Parameters:
memory
- The memory that should be overwritten.
-
implementationName
public String implementationName()
Description copied from interface:MemoryManager
Get the name for this implementation, which can be used for finding this particular implementation via theMemoryManager.lookupImplementation(String)
method.- Specified by:
implementationName
in interfaceMemoryManager
- Returns:
- The name of this memory managers implementation.
-
-