|
Flow
Documentation for the Flow C++ Library
|
Fixed-size buddy allocator implementing the MemoryResource interface. The min block size is 1 byte, the maximum is 1<<64 bytes. More...
#include <flow_buddy_memory_resource.h>
Classes | |
| struct | BuddyBlock |
Public Member Functions | |
| BuddyMemoryResource (void *buffer, std::size_t capacity, std::size_t alignment=alignof(std::max_align_t)) | |
| Constructs a buddy allocator over a user-provided buffer. | |
| virtual void * | allocateImp (std::size_t bytes, std::size_t alignment) override |
| virtual void | deallocateImp (void *address, std::size_t bytes, std::size_t alignment) override |
| Public Member Functions inherited from flow::MemoryResource | |
| virtual | ~MemoryResource ()=default |
| void * | allocate (std::size_t bytes, std::size_t alignment=alignof(std::max_align_t)) |
| void | deallocate (void *address, std::size_t bytes, std::size_t alignment=alignof(std::max_align_t)) |
Private Member Functions | |
| std::size_t | getLevelSize (std::size_t level) const noexcept |
| BuddyBlock * | popFront (std::size_t level) noexcept |
| void | pushFront (BuddyBlock *block, std::size_t level) noexcept |
| bool | isEmpty (std::size_t level) const noexcept |
| BuddyBlock * | getBuddy (BuddyBlock *block, std::size_t blockSize) const noexcept |
| bool | eraseBlock (BuddyBlock *block, std::size_t level) noexcept |
Private Attributes | |
| std::byte * | beginBuffer_ |
| std::size_t | capacity_ |
| BuddyBlock | freeList_ [kMaxLevel] |
Static Private Attributes | |
| static constexpr std::size_t | kMaxLevel = 64 |
Fixed-size buddy allocator implementing the MemoryResource interface. The min block size is 1 byte, the maximum is 1<<64 bytes.
Definition at line 13 of file flow_buddy_memory_resource.h.
|
inlineexplicit |
Constructs a buddy allocator over a user-provided buffer.
| buffer | Pointer to buffer. |
| capacity | Buffer size in bytes. |
| alignment | Required alignment. |
| std::bad_alloc | If buffer cannot satisfy alignment. |
Definition at line 76 of file flow_buddy_memory_resource.h.
References beginBuffer_, capacity_, freeList_, and pushFront().
|
inlineoverridevirtual |
Implements flow::MemoryResource.
Definition at line 91 of file flow_buddy_memory_resource.h.
References getLevelSize(), isEmpty(), kMaxLevel, popFront(), and pushFront().
|
inlineoverridevirtual |
Implements flow::MemoryResource.
Definition at line 117 of file flow_buddy_memory_resource.h.
References eraseBlock(), getBuddy(), getLevelSize(), kMaxLevel, and pushFront().
|
inlineprivatenoexcept |
Definition at line 56 of file flow_buddy_memory_resource.h.
References freeList_, and flow::BuddyMemoryResource::BuddyBlock::next.
Referenced by deallocateImp().
|
inlineprivatenoexcept |
Definition at line 45 of file flow_buddy_memory_resource.h.
References beginBuffer_, and capacity_.
Referenced by deallocateImp().
|
inlineprivatenoexcept |
Definition at line 24 of file flow_buddy_memory_resource.h.
Referenced by allocateImp(), and deallocateImp().
|
inlineprivatenoexcept |
Definition at line 41 of file flow_buddy_memory_resource.h.
References freeList_.
Referenced by allocateImp().
|
inlineprivatenoexcept |
Definition at line 28 of file flow_buddy_memory_resource.h.
References freeList_, and flow::BuddyMemoryResource::BuddyBlock::next.
Referenced by allocateImp().
|
inlineprivatenoexcept |
Definition at line 35 of file flow_buddy_memory_resource.h.
References freeList_, and kMaxLevel.
Referenced by allocateImp(), BuddyMemoryResource(), and deallocateImp().
|
private |
Definition at line 20 of file flow_buddy_memory_resource.h.
Referenced by BuddyMemoryResource(), and getBuddy().
|
private |
Definition at line 21 of file flow_buddy_memory_resource.h.
Referenced by BuddyMemoryResource(), and getBuddy().
|
private |
Definition at line 22 of file flow_buddy_memory_resource.h.
Referenced by BuddyMemoryResource(), eraseBlock(), isEmpty(), popFront(), and pushFront().
|
staticconstexprprivate |
Definition at line 18 of file flow_buddy_memory_resource.h.
Referenced by allocateImp(), deallocateImp(), and pushFront().