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 {
28template <
typename OffsetType>
29using BestFitBlock = DetailedBlock<OffsetType, GenericFastSortedItem>;
40template <
typename BlockType = BestFitBlock<u
intptr_t>>
59 BlockType* block =
nullptr;
61 block = small_bucket_.RemoveCompatible(layout);
62 if (block !=
nullptr) {
63 return BlockType::AllocFirst(std::move(block), layout);
66 block = large_bucket_.RemoveCompatible(layout);
67 if (block !=
nullptr) {
68 return BlockType::AllocFirst(std::move(block), layout);
76 if (!large_bucket_.Remove(block)) {
77 std::ignore = small_bucket_.Remove(block);
84 std::ignore = small_bucket_.Add(block);
86 std::ignore = large_bucket_.Add(block);
Definition: best_fit.h:41
void RecycleBlock(BlockType &block) override
Definition: best_fit.h:82
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: best_fit.h:57
constexpr BestFitAllocator()=default
Constexpr constructor. Callers must explicitly call Init.
BestFitAllocator(ByteSpan region)
Definition: best_fit.h:53
void ReserveBlock(BlockType &block) override
Definition: best_fit.h:74
Definition: block_allocator.h:104
void Init(ByteSpan region)
Definition: block_allocator.h:281
Definition: fast_sorted.h:63