Class AATreeFileAllocator
- All Implemented Interfaces:
Iterable<Region>, Collection<Region>, SequencedCollection<Region>, SequencedSet<Region>, Set<Region>, SortedSet<Region>
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:
- if the requested size is smaller than or equal to the smallest contiguous region then find the smallest contiguous region and use it
- if the current node is perfectly sized then use it
- pick the child with the smallest contiguous subnode that will hold us - and then go to 2
- 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class AATreeSet
AATreeSet.AbstractTreeNode<E>, AATreeSet.Node<E> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final longprivate static final intprivate static final intprivate longprivate static final boolean -
Constructor Summary
ConstructorsConstructorDescriptionAATreeFileAllocator(long size) Create an abstract allocator using the given buffer source and initial size.AATreeFileAllocator(long size, DataInput input) -
Method Summary
Modifier and TypeMethodDescriptionlongallocate(long size) private voidlongcapacity()private Regionfind(long size) Find a region of the given size.voidfree(long address, long length) private voidprivate voidlongoccupied()(package private) voidpersist(DataOutput output) (package private) voidpersist(DataOutput output, Region r) toString()Methods inherited from class AATreeSet
add, clear, comparator, first, getRoot, headSet, isEmpty, iterator, last, remove, size, subSet, tailSetMethods inherited from class AbstractSet
equals, hashCode, removeAllMethods inherited from class AbstractCollection
addAll, contains, containsAll, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface Set
addAll, contains, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArrayMethods inherited from interface SortedSet
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed, spliterator
-
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
- Throws:
IOException
-
-
Method Details
-
allocate
public long allocate(long size) -
free
public void free(long address, long length) -
removeAndReturn
- Overrides:
removeAndReturnin classAATreeSet<Region>
-
find
-
occupied
public long occupied() -
capacity
public long capacity() -
allocated
-
freed
-
free
-
find
Find a region of the given size. -
toString
- Overrides:
toStringin classAbstractCollection<Region>
-
persist
- Throws:
IOException
-
persist
- Throws:
IOException
-