#include <buddy_allocator.h>
|
| GenericBuddyAllocator (span< BucketType > buckets, size_t min_outer_size) |
|
void | Init (ByteSpan region) |
| Sets the memory used to allocate blocks.
|
|
void * | Allocate (Layout layout) |
|
void | Deallocate (void *ptr) |
|
size_t | GetCapacity () const |
| Returns the total capacity of this allocator.
|
|
Result< Layout > | GetLayout (const void *ptr) const |
| Returns the allocated layout for a given pointer.
|
|
void | CrashIfAllocated () |
|
|
static constexpr Capabilities | kCapabilities |
|
static constexpr size_t | kDefaultMinOuterSize = 16 |
|
static constexpr size_t | kDefaultNumBuckets = 16 |
|
Size-independent buddy allocator.
This allocator allocates blocks of memory whose sizes are powers of two. See also https://en.wikipedia.org/wiki/Buddy_memory_allocation.
Compared to BuddyAllocator
, this implementation is size-agnostic with respect to the number of buckets.
◆ GenericBuddyAllocator()
pw::allocator::internal::GenericBuddyAllocator::GenericBuddyAllocator |
( |
span< BucketType > |
buckets, |
|
|
size_t |
min_outer_size |
|
) |
| |
Constructs a buddy allocator.
- Parameters
-
[in] | buckets | Storage for buckets of free blocks. |
[in] | min_outer_size | Outer size of the blocks in the first bucket. |
◆ Allocate()
void * pw::allocator::internal::GenericBuddyAllocator::Allocate |
( |
Layout |
layout | ) |
|
Allocates a block of memory with the specified size and alignment.
Returns nullptr
if the allocation cannot be made, or the layout
has a size of 0.
- Parameters
-
[in] | layout | Describes the memory to be allocated. |
◆ CrashIfAllocated()
void pw::allocator::internal::GenericBuddyAllocator::CrashIfAllocated |
( |
| ) |
|
Ensures all allocations have been freed. Crashes with a diagnostic message If any allocations remain outstanding.
◆ Deallocate()
void pw::allocator::internal::GenericBuddyAllocator::Deallocate |
( |
void * |
ptr | ) |
|
Releases a previously-allocated block of memory.
The given pointer must have been previously provided by this memory resource; otherwise the behavior is undefined.
- Parameters
-
[in] | ptr | Pointer to previously-allocated memory. |
◆ kCapabilities
constexpr Capabilities pw::allocator::internal::GenericBuddyAllocator::kCapabilities |
|
staticconstexpr |
Initial value:=
kImplementsGetUsableLayout | kImplementsGetAllocatedLayout |
kImplementsGetCapacity | kImplementsRecognizes
The documentation for this class was generated from the following file: