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 {
29template <
typename OffsetType = u
intptr_t>
30using BucketBlock = DetailedBlock<OffsetType, UnorderedItem>;
55template <
typename BlockType = BucketBlock<>,
56 size_t kMinInnerSize = 32,
57 size_t kNumBuckets = 5>
65 size_t max_inner_size = kMinInnerSize;
66 for (
auto& bucket : span(buckets_.data(), kNumBuckets - 1)) {
67 bucket.set_max_inner_size(max_inner_size);
83 for (
auto& bucket : buckets_) {
91 for (
auto& bucket : buckets_) {
92 if (layout.size() <= bucket.max_inner_size()) {
93 BlockType* block = bucket.RemoveCompatible(layout);
94 if (block !=
nullptr) {
95 return BlockType::AllocFirst(std::move(block), layout);
104 for (
auto& bucket : buckets_) {
105 if (block.InnerSize() <= bucket.max_inner_size()) {
106 std::ignore = bucket.Remove(block);
114 for (
auto& bucket : buckets_) {
115 if (block.InnerSize() <= bucket.max_inner_size()) {
116 std::ignore = bucket.Add(block);
122 std::array<UnorderedBucket<BlockType>, kNumBuckets> buckets_;
Definition: block_allocator.h:104
void Init(ByteSpan region)
Definition: block_allocator.h:281
Definition: bucket_allocator.h:58
void RecycleBlock(BlockType &block) override
Definition: bucket_allocator.h:113
constexpr BucketAllocator()
Constexpr constructor. Callers must explicitly call Init.
Definition: bucket_allocator.h:64
BucketAllocator(ByteSpan region)
Definition: bucket_allocator.h:78
void ReserveBlock(BlockType &block) override
Definition: bucket_allocator.h:103
BlockResult< BlockType > ChooseBlock(Layout layout) override
Definition: bucket_allocator.h:90