Class ArenaMemoryAllocator

java.lang.Object
org.apache.druid.frame.allocation.ArenaMemoryAllocator
All Implemented Interfaces:
MemoryAllocator

public class ArenaMemoryAllocator extends Object implements MemoryAllocator
Allocator that uses a reusable WritableMemory arena. The allocator maintains a high watermark that is reset to zero when all outstanding allocations have been freed.
  • Method Details

    • create

      public static ArenaMemoryAllocator create(ByteBuffer buffer)
      Creates an allocator based on a specific ByteBuffer. The buffer is never freed, so to ensure proper cleanup when the allocator is discarded, this buffer must be on-heap (so it can be garbage collected) rather than off-heap.
    • createOnHeap

      public static ArenaMemoryAllocator createOnHeap(int capacity)
      Creates an allocator of a specific size using an on-heap ByteBuffer.
    • allocate

      public Optional<ResourceHolder<org.apache.datasketches.memory.WritableMemory>> allocate(long size)
      Description copied from interface: MemoryAllocator
      Allocates a block of memory of capacity . Returns empty if no more memory is available. The memory can be freed by closing the returned ResourceHolder. The returned WritableMemory object will use little-endian byte order.
      Specified by:
      allocate in interface MemoryAllocator
    • available

      public long available()
      Description copied from interface: MemoryAllocator
      Returns the number of bytes available for allocations. May return Long.MAX_VALUE if there is no inherent limit. This generally does not mean you can actually allocate 9 exabytes.
      Specified by:
      available in interface MemoryAllocator
    • capacity

      public long capacity()
      Description copied from interface: MemoryAllocator
      Returns the number of bytes managed by this allocator. When no memory has been allocated yet, this is identical to MemoryAllocator.available(). May return Long.MAX_VALUE if there is no inherent limit. This generally does not mean you can actually allocate 9 exabytes.
      Specified by:
      capacity in interface MemoryAllocator