Class MemorySegmentRequestExample

java.lang.Object
org.apache.datasketches.common.MemorySegmentRequestExample
All Implemented Interfaces:
MemorySegmentRequest

public final class MemorySegmentRequestExample extends Object implements MemorySegmentRequest
This is an example of a possible implementation of the MemorySegmentRequest interface where all requested segments are allocated off-heap. A local ConcurrentHashMap tracks a newly created confined Arena for every new MemorySegment allocated off-heap. This allows individual segments to be freed immediately upon receiving the requestClose(MemorySegment) call.
  • Constructor Details

    • MemorySegmentRequestExample

      public MemorySegmentRequestExample()
      No argument constructor.
  • Method Details

    • request

      public MemorySegment request(long newByteSize)
      Request a new off-heap MemorySegment with the given newByteSeze. An internal confined Arena is created to exclusively manage the new segment and it is associated with the new segment with a ConcurrentHashMap.
      Specified by:
      request in interface MemorySegmentRequest
      Parameters:
      newByteSize - The new byteSize being requested.
      Returns:
      new MemorySegment with the requested byteSize.
    • requestClose

      public void requestClose(MemorySegment segKey)
      Description copied from interface: MemorySegmentRequest
      Request to close the given MemorySegment. Because we do not have a reference to an Arena, the default here is to do nothing. It is up to the user to override this as appropriate.
      Specified by:
      requestClose in interface MemorySegmentRequest
      Parameters:
      segKey - the previous MemorySegment to be closed.
    • cleanup

      public void cleanup()
      This closes any unclosed, off-heap MemorySegments and removes all mappings from the map.