Class AATreeFileAllocator

All Implemented Interfaces:
Iterable<Region>, Collection<Region>, SequencedCollection<Region>, SequencedSet<Region>, Set<Region>, SortedSet<Region>

public class AATreeFileAllocator extends AATreeSet<Region>
An augmented AA tree based allocator.

This allocator maintains an augmented AA tree of free regions. Tree nodes are augmented with the size of the maximum and minimum contiguous free region linked beneath them in the tree. Regions being freed are merged with adjacent free regions and the tree structure updated to reflect the resultant region.

Allocations are performed in a very approximate best fit manner. Assuming that there is a large enough free region in the tree, tree navigation decisions proceed as follows:

  1. if the requested size is smaller than or equal to the smallest contiguous region then find the smallest contiguous region and use it
  2. if the current node is perfectly sized then use it
  3. pick the child with the smallest contiguous subnode that will hold us - and then go to 2
  4. if no such child exists use the current node

This allocator will experience bad fragmentation affects when not used with uniformly sized allocations calls. Since the AA Tree is stored in the Java object heap this can lead to excessive heap usage.

  • Field Details

    • VALIDATING

      private static final boolean VALIDATING
    • MAGIC

      private static final int MAGIC
      See Also:
    • MAGIC_REGION

      private static final int MAGIC_REGION
      See Also:
    • capacity

      private final long capacity
    • occupied

      private long occupied
  • Constructor Details

    • AATreeFileAllocator

      public AATreeFileAllocator(long size)
      Create an abstract allocator using the given buffer source and initial size.

      This initial size will be used to size the buffer returned from the clear call.

      Parameters:
      size - initial buffer size
    • AATreeFileAllocator

      public AATreeFileAllocator(long size, DataInput input) throws IOException
      Throws:
      IOException
  • Method Details