19#include "pw_allocator/allocator.h"
20#include "pw_allocator/block/basic.h"
21#include "pw_allocator/bucket/unordered.h"
22#include "pw_bytes/span.h"
23#include "pw_containers/vector.h"
24#include "pw_status/try.h"
26namespace pw::allocator {
53 static constexpr size_t DefaultAlignment() {
return 1; }
54 static constexpr size_t BlockOverhead() {
return sizeof(
BuddyBlock); }
55 static constexpr size_t MinInnerSize() {
return sizeof(
UnorderedItem); }
56 constexpr size_t OuterSizeUnchecked()
const {
return 1U << outer_size_log2_; }
58 uint8_t outer_size_log2_;
71 kImplementsGetUsableLayout | kImplementsGetAllocatedLayout |
72 kImplementsGetCapacity | kImplementsRecognizes;
74 static constexpr size_t kDefaultMinOuterSize = 16;
75 static constexpr size_t kDefaultNumBuckets = 16;
82 size_t min_outer_size);
103 size_t min_outer_size_ = 0;
132template <
size_t kMinOuterSize_ =
133 internal::GenericBuddyAllocator::kDefaultMinOuterSize,
135 internal::GenericBuddyAllocator::kDefaultNumBuckets>
141 static constexpr size_t kMinOuterSize = kMinOuterSize_;
143 static_assert((kMinOuterSize & (kMinOuterSize - 1)) == 0,
144 "kMinOuterSize must be a power of 2");
159 std::array<UnorderedBucket<internal::BuddyBlock>, kNumBuckets> buckets_;
Definition: allocator.h:42
Definition: status_with_size.h:51
Definition: buddy_allocator.h:136
constexpr BuddyAllocator()
Constructs an allocator. Callers must call Init.
Definition: buddy_allocator.h:147
BuddyAllocator(ByteSpan region)
Definition: buddy_allocator.h:154
Definition: capability.h:65
Definition: unordered.h:44
Definition: unordered.h:32
Definition: buddy_allocator.h:35
static BuddyBlock * Merge(BuddyBlock *&&left, BuddyBlock *&&right)
Merges two blocks together.
StatusWithSize CanAlloc(Layout layout) const
BuddyBlock * Split()
Splits a block in half and returns the new block.
Definition: buddy_allocator.h:68
void DoDeallocate(void *ptr) override
void InitBuckets(span< UnorderedBucket< BuddyBlock > > buckets, size_t min_outer_size)
Result< Layout > DoGetInfo(InfoType info_type, const void *ptr) const override
void * DoAllocate(Layout layout) override
void Init(ByteSpan region)
Sets the memory used to allocate blocks.
Definition: span_impl.h:235