Class MemorySegmentMemoryManager

java.lang.Object
eu.cloudnetservice.driver.impl.network.netty.memory.MemorySegmentMemoryManager
All Implemented Interfaces:
io.netty5.buffer.MemoryManager

@Internal public final class MemorySegmentMemoryManager extends Object implements io.netty5.buffer.MemoryManager
Custom implementation of a netty memory manager based on memory segments. Direct buffers obtained from this implementation are, in contrast to the netty implementation, not obtained from a shared arena. This allows for more efficient freeing of the allocated memory segments.
Since:
4.0
  • Constructor Details

    • MemorySegmentMemoryManager

      public MemorySegmentMemoryManager()
  • Method Details

    • constructBuffer

      @NonNull private static @NonNull io.netty5.buffer.Buffer constructBuffer(@NonNull @NonNull MemorySegment segment, @NonNull @NonNull io.netty5.buffer.AllocatorControl allocatorControl, @NonNull @NonNull Function<io.netty5.buffer.Drop<io.netty5.buffer.Buffer>, io.netty5.buffer.Drop<io.netty5.buffer.Buffer>> dropDecorator, @Nullable @Nullable io.netty5.buffer.Drop<io.netty5.buffer.Buffer> segmentDrop)
      Constructs a new buffer instance for the given memory segment.
      Parameters:
      segment - the segment to use for the constructed buffer.
      allocatorControl - the controller for the allocator that requested the allocation.
      dropDecorator - function to decorate the drop that should be used by the constructed buffer.
      segmentDrop - the base drop to free the given segment, null in case there is nothing to drop.
      Returns:
      a new buffer instance backed by the given memory segment.
      Throws:
      NullPointerException - if the given segment, alloc control or drop decorator is null.
    • allocateShared

      @NonNull public @NonNull io.netty5.buffer.Buffer allocateShared(@NonNull @NonNull io.netty5.buffer.AllocatorControl allocatorControl, long size, @NonNull @NonNull Function<io.netty5.buffer.Drop<io.netty5.buffer.Buffer>, io.netty5.buffer.Drop<io.netty5.buffer.Buffer>> dropDecorator, @NonNull @NonNull io.netty5.buffer.AllocationType allocationType)
      Specified by:
      allocateShared in interface io.netty5.buffer.MemoryManager
    • allocateConstChild

      @NonNull public @NonNull io.netty5.buffer.Buffer allocateConstChild(@NonNull @NonNull io.netty5.buffer.Buffer readOnlyConstParent)
      Specified by:
      allocateConstChild in interface io.netty5.buffer.MemoryManager
    • unwrapRecoverableMemory

      @NonNull public @NonNull Object unwrapRecoverableMemory(@NonNull @NonNull io.netty5.buffer.Buffer buf)
      Specified by:
      unwrapRecoverableMemory in interface io.netty5.buffer.MemoryManager
    • recoverMemory

      @NonNull public @NonNull io.netty5.buffer.Buffer recoverMemory(@NonNull @NonNull io.netty5.buffer.AllocatorControl allocatorControl, @NonNull @NonNull Object recoverableMemory, @NonNull @NonNull io.netty5.buffer.Drop<io.netty5.buffer.Buffer> drop)
      Specified by:
      recoverMemory in interface io.netty5.buffer.MemoryManager
    • sliceMemory

      @NonNull public @NonNull Object sliceMemory(@NonNull @NonNull Object memory, int offset, int length)
      Specified by:
      sliceMemory in interface io.netty5.buffer.MemoryManager
    • clearMemory

      public void clearMemory(@NonNull @NonNull Object memory)
      Specified by:
      clearMemory in interface io.netty5.buffer.MemoryManager
    • sizeOf

      public int sizeOf(@NonNull @NonNull Object memory)
      Specified by:
      sizeOf in interface io.netty5.buffer.MemoryManager
    • implementationName

      @NonNull public @NonNull String implementationName()
      Specified by:
      implementationName in interface io.netty5.buffer.MemoryManager