20#include "pw_allocator/block/detailed_block.h"
21#include "pw_allocator/block_allocator.h"
22#include "pw_allocator/bucket/unordered.h"
23#include "pw_status/try.h"
25namespace pw::allocator {
31template <
typename OffsetType = u
intptr_t>
57template <
typename BlockType = BucketBlock<>>
67 size_t max_inner_size);
89template <
typename BlockType = BucketBlock<>,
90 size_t kMinInnerSize = 32,
91 size_t kNumBuckets = 5>
113 std::array<UnorderedBucket<BlockType>, kNumBuckets> buckets_;
120template <
typename BlockType>
124 for (
auto& bucket : buckets_.subspan(0, buckets_.size() - 1)) {
125 bucket.set_max_inner_size(max_inner_size);
126 max_inner_size <<= 1;
130template <
typename BlockType>
132 for (
auto b = buckets_.rbegin(); b != buckets_.rend(); ++b) {
133 const BlockType* largest = b->FindLargest();
134 if (largest !=
nullptr) {
135 return largest->InnerSize();
141template <
typename BlockType>
144 for (
auto& bucket : buckets_) {
145 if (bucket.max_inner_size() < layout.size()) {
148 BlockType* block = bucket.RemoveCompatible(layout);
149 if (block !=
nullptr) {
150 return BlockType::AllocFirst(std::move(block), layout);
156template <
typename BlockType>
158 for (
auto& bucket : buckets_) {
159 if (block.InnerSize() <= bucket.max_inner_size()) {
160 std::ignore = bucket.Remove(block);
166template <
typename BlockType>
168 for (
auto& bucket : buckets_) {
169 if (block.InnerSize() <= bucket.max_inner_size()) {
170 std::ignore = bucket.Add(block);
176template <
typename BlockType,
size_t kMinInnerSize,
size_t kNumBuckets>
178 for (
auto& bucket : buckets_) {
static constexpr Status NotFound()
Definition: status.h:190
Definition: bucket_allocator.h:58
void ReserveBlock(BlockType &block) override
Definition: bucket_allocator.h:157
constexpr void InitBuckets(span< UnorderedBucket< BlockType > > buckets, size_t max_inner_size)
Configures bucket sizes.
Definition: bucket_allocator.h:121
void RecycleBlock(BlockType &block) override
Definition: bucket_allocator.h:167
size_t DoGetMaxAllocatable() override
Definition: bucket_allocator.h:131
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: bucket_allocator.h:142
Definition: block_allocator.h:98
void Init(ByteSpan region)
Definition: block_allocator.h:303
Definition: bucket_allocator.h:92
constexpr BucketAllocator()
Constexpr constructor. Callers must explicitly call Init.
Definition: bucket_allocator.h:98
BucketAllocator(ByteSpan region)
Definition: bucket_allocator.h:106
Definition: detailed_block.h:88
Definition: unordered.h:44
Definition: span_impl.h:235