FreeTree
(ParentAllocator);FreeTree
include:FreeTree
frees everything and then tries the parent allocator again.Upon deallocation, the deallocated block is inserted in the internallymaintained free tree (not returned to the parent). The free tree is not keptbalanced. Instead, it has a last-in-first-out flavor because newly insertedblocks are rotated to the root of the tree. That way allocations are cachefriendly and also frequently used sizes are more likely to be found quickly,whereas seldom used sizes migrate to the leaves of the tree.FreeTree
rounds up small allocations to at least4 * size_t.sizeof,which on 64-bit system is one cache line size. If very small objects need tobe efficiently allocated, theFreeTree
should be fronted with anappropriate small object allocator.The following methods are defined ifParentAllocator defines them, and forward to it:allocateAll,expand,owns,reallocate.alignment
;goodAllocSize
(size_ts
);allocate
(size_tn
);n
bytes of memory. First consults the free tree, and returns from it if a suitably sized block is found. Otherwise, the parent allocator is tried. If allocation from the parent succeeds, the allocated block is returned. Otherwise, the free tree tries an alternate strategy: If ParentAllocator definesdeallocate,FreeTree releases all of its contents and tries again.TODOSplitting and coalescing should be implemented ifParentAllocator does not defineddeallocate.
deallocate
(void[]b
);b
into the free tree.clear
();deallocateAll
();deallocateAll
exists, and forwards to it. Also nullifies the free tree (it's assumed the parent frees all memory stil managed by the free tree).