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 = WorstFitBlock<u
intptr_t>>
74 SmallBucket small_bucket_;
75 LargeBucket large_bucket_;
82template <
typename BlockType>
84 const BlockType* largest = large_bucket_.empty()
85 ? small_bucket_.FindLargest()
86 : large_bucket_.FindLargest();
87 return largest ==
nullptr ? 0 : largest->InnerSize();
90template <
typename BlockType>
93 BlockType* block = large_bucket_.RemoveCompatible(layout);
94 if (block !=
nullptr) {
95 return BlockType::AllocFirst(std::move(block), layout);
97 block = small_bucket_.RemoveCompatible(layout);
98 if (block !=
nullptr) {
99 return BlockType::AllocFirst(std::move(block), layout);
104template <
typename BlockType>
107 if (!large_bucket_.Remove(block)) {
108 std::ignore = small_bucket_.Remove(block);
112template <
typename BlockType>
115 std::ignore = small_bucket_.Add(block);
117 std::ignore = large_bucket_.Add(block);
static constexpr Status NotFound()
Definition: status.h:190
Definition: block_allocator.h:98
void Init(ByteSpan region)
Definition: block_allocator.h:303
Definition: detailed_block.h:88
Definition: fast_sorted.h:35
Definition: fast_sorted.h:114
Definition: worst_fit.h:43
constexpr WorstFitAllocator()=default
Constexpr constructor. Callers must explicitly call Init.
WorstFitAllocator(ByteSpan region)
Definition: worst_fit.h:59
size_t DoGetMaxAllocatable() override
Definition: worst_fit.h:83
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: worst_fit.h:91
void ReserveBlock(BlockType &block) override
Definition: worst_fit.h:105
void RecycleBlock(BlockType &block) override
Definition: worst_fit.h:113