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<>,
58 size_t kMinInnerSize = 32,
59 size_t kNumBuckets = 5>
67 size_t max_inner_size = kMinInnerSize;
68 for (
auto& bucket :
span(buckets_.data(), kNumBuckets - 1)) {
69 bucket.set_max_inner_size(max_inner_size);
85 for (
auto& bucket : buckets_) {
93 for (
auto b = buckets_.rbegin(); b != buckets_.rend(); ++b) {
94 const BlockType* largest = b->FindLargest();
95 if (largest !=
nullptr) {
96 return largest->InnerSize();
104 for (
auto& bucket : buckets_) {
105 if (bucket.max_inner_size() < layout.size()) {
108 BlockType* block = bucket.RemoveCompatible(layout);
109 if (block !=
nullptr) {
110 return BlockType::AllocFirst(std::move(block), layout);
118 for (
auto& bucket : buckets_) {
119 if (block.InnerSize() <= bucket.max_inner_size()) {
120 std::ignore = bucket.Remove(block);
128 for (
auto& bucket : buckets_) {
129 if (block.InnerSize() <= bucket.max_inner_size()) {
130 std::ignore = bucket.Add(block);
136 std::array<UnorderedBucket<BlockType>, kNumBuckets> buckets_;
Definition: block_allocator.h:106
void Init(ByteSpan region)
Definition: block_allocator.h:310
Definition: bucket_allocator.h:60
void RecycleBlock(BlockType &block) override
Definition: bucket_allocator.h:127
constexpr BucketAllocator()
Constexpr constructor. Callers must explicitly call Init.
Definition: bucket_allocator.h:66
BucketAllocator(ByteSpan region)
Definition: bucket_allocator.h:80
size_t DoGetMaxAllocatable() override
Definition: bucket_allocator.h:92
void ReserveBlock(BlockType &block) override
Definition: bucket_allocator.h:117
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: bucket_allocator.h:103
Definition: detailed_block.h:88
Definition: span_impl.h:235