Package io.netty5.buffer.api.unsafe
Class UnsafeMemoryManager
- java.lang.Object
-
- io.netty5.buffer.api.unsafe.UnsafeMemoryManager
-
- All Implemented Interfaces:
MemoryManager
public final class UnsafeMemoryManager extends Object implements MemoryManager
This memory manager produces and managesBufferinstances that are usingUnsafeto allocate and access memory.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 UnsafeMemoryManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BufferallocateConstChild(Buffer readOnlyConstParent)Allocates a constant buffer based on the given parent.BufferallocateShared(AllocatorControl control, long size, Function<Drop<Buffer>,Drop<Buffer>> dropDecorator, AllocationType allocationType)Allocates a shared buffer.StringimplementationName()Get the name for this implementation, which can be used for finding this particular implementation via theMemoryManager.lookupImplementation(String)method.BufferrecoverMemory(AllocatorControl allocatorControl, Object recoverableMemory, Drop<Buffer> drop)Recover the memory from a priorMemoryManager.unwrapRecoverableMemory(Buffer)call, and wrap it in aBufferinstance.ObjectsliceMemory(Object memory, int offset, int length)Produces a slice of the given internal memory representation object.ObjectunwrapRecoverableMemory(Buffer buf)Create an object that represents the internal memory of the given buffer.
-
-
-
Method Detail
-
allocateShared
public Buffer allocateShared(AllocatorControl control, long size, Function<Drop<Buffer>,Drop<Buffer>> dropDecorator, AllocationType allocationType)
Description copied from interface:MemoryManagerAllocates 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 theBufferinterface.- Specified by:
allocateSharedin interfaceMemoryManager- Parameters:
control- 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 managersDropinstance. TheDropinstance 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
Bufferinstance with the given configuration.
-
allocateConstChild
public Buffer allocateConstChild(Buffer readOnlyConstParent)
Description copied from interface:MemoryManagerAllocates 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:
allocateConstChildin 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:MemoryManagerCreate an object that represents the internal memory of the given buffer.- Specified by:
unwrapRecoverableMemoryin 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:MemoryManagerRecover the memory from a priorMemoryManager.unwrapRecoverableMemory(Buffer)call, and wrap it in aBufferinstance.- Specified by:
recoverMemoryin interfaceMemoryManager- Parameters:
allocatorControl- The allocator control to attach to the buffer.recoverableMemory- The opaque memory to use for the buffer.drop- TheDropinstance to use when the buffer is closed.- Returns:
- A
Bufferinstance backed by the given recovered memory.
-
sliceMemory
public Object sliceMemory(Object memory, int offset, int length)
Description copied from interface:MemoryManagerProduces a slice of the given internal memory representation object.- Specified by:
sliceMemoryin 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.
-
implementationName
public String implementationName()
Description copied from interface:MemoryManagerGet the name for this implementation, which can be used for finding this particular implementation via theMemoryManager.lookupImplementation(String)method.- Specified by:
implementationNamein interfaceMemoryManager- Returns:
- The name of this memory managers implementation.
-
-