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>>
74 SmallBucket small_bucket_;
75 LargeBucket large_bucket_;
80template <
typename BlockType>
82 const BlockType* largest = large_bucket_.empty()
83 ? small_bucket_.FindLargest()
84 : large_bucket_.FindLargest();
85 return largest ==
nullptr ? 0 : largest->InnerSize();
88template <
typename BlockType>
91 BlockType* block =
nullptr;
93 block = small_bucket_.RemoveCompatible(layout);
94 if (block !=
nullptr) {
95 return BlockType::AllocFirst(std::move(block), layout);
98 block = large_bucket_.RemoveCompatible(layout);
99 if (block !=
nullptr) {
100 return BlockType::AllocFirst(std::move(block), layout);
105template <
typename BlockType>
108 if (!large_bucket_.Remove(block)) {
109 std::ignore = small_bucket_.Remove(block);
113template <
typename BlockType>
116 std::ignore = small_bucket_.Add(block);
118 std::ignore = large_bucket_.Add(block);
static constexpr Status NotFound()
Definition: status.h:190
Definition: best_fit.h:43
constexpr BestFitAllocator()=default
Constexpr constructor. Callers must explicitly call Init.
BestFitAllocator(ByteSpan region)
Definition: best_fit.h:59
Definition: block_allocator.h:98
void Init(ByteSpan region)
Definition: block_allocator.h:303
Definition: detailed_block.h:88
Definition: fast_sorted.h:65
Definition: fast_sorted.h:35
void RecycleBlock(BlockType &block) override
Definition: best_fit.h:114
size_t DoGetMaxAllocatable() override
Definition: best_fit.h:81
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: best_fit.h:89
void ReserveBlock(BlockType &block) override
Definition: best_fit.h:106