19#include "pw_allocator/block/detailed_block.h"
20#include "pw_allocator/block_allocator.h"
21#include "pw_allocator/bucket/fast_sorted.h"
22#include "pw_allocator/bucket/sorted.h"
23#include "pw_allocator/config.h"
25namespace pw::allocator {
30template <
typename OffsetType>
42template <
typename BlockType = BestFitBlock<u
intptr_t>>
64 const BlockType* largest = large_bucket_.
empty()
67 return largest ==
nullptr ? 0 : largest->InnerSize();
73 BlockType* block =
nullptr;
76 if (block !=
nullptr) {
77 return BlockType::AllocFirst(std::move(block), layout);
81 if (block !=
nullptr) {
82 return BlockType::AllocFirst(std::move(block), layout);
90 if (!large_bucket_.
Remove(block)) {
91 std::ignore = small_bucket_.
Remove(block);
98 std::ignore = small_bucket_.
Add(block);
100 std::ignore = large_bucket_.
Add(block);
104 SmallBucket small_bucket_;
105 LargeBucket large_bucket_;
Definition: best_fit.h:43
void RecycleBlock(BlockType &block) override
Definition: best_fit.h:96
size_t DoGetMaxAllocatable() override
Definition: best_fit.h:63
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: best_fit.h:71
constexpr BestFitAllocator()=default
Constexpr constructor. Callers must explicitly call Init.
BestFitAllocator(ByteSpan region)
Definition: best_fit.h:59
void ReserveBlock(BlockType &block) override
Definition: best_fit.h:88
Definition: block_allocator.h:106
void Init(ByteSpan region)
Definition: block_allocator.h:310
Definition: detailed_block.h:88
Definition: fast_sorted.h:65
Definition: fast_sorted.h:35
bool Remove(BlockType &block)
Definition: base.h:118
const BlockType * FindLargest() const
Definition: base.h:103
bool Add(BlockType &block)
Definition: base.h:89
constexpr bool empty() const
Returns whether this buckets contains any free blocks.
Definition: base.h:70
BlockType * RemoveCompatible(Layout layout)
Definition: base.h:129