1#ifndef included_BuddyAllocator
2#define included_BuddyAllocator
20 size_t blockSize = 1024,
21 std::function<
void *(
size_t )> allocator = ::malloc,
22 std::function<
void(
void * )> deallocator = ::free,
23 std::function<
void(
void *,
size_t )> zero = [](
void *,
size_t ) {} );
44 static constexpr bool isLIFO() {
return false; }
66 std::function<void(
void *,
size_t )>
d_zero;
69 inline size_t N_blocks()
const {
return ( (
size_t) 0x01 ) <<
d_n; }
void * allocate(size_t bytes)
Allocate memory.
static constexpr bool isLIFO()
Check if the allocator is Last-In-First-Out (LIFO)
std::function< void(void *, size_t)> d_zero
BuddyAllocator(const BuddyAllocator &)=delete
~BuddyAllocator()
Destructor.
BuddyAllocator(size_t bytes, size_t blockSize=1024, std::function< void *(size_t)> allocator=::malloc, std::function< void(void *)> deallocator=::free, std::function< void(void *, size_t)> zero=[](void *, size_t) {})
Default constructor.
BuddyAllocator & operator=(BuddyAllocator &&)
void blockFree(int level, int block)
BuddyAllocator & operator=(const BuddyAllocator &)=delete
std::function< void(void *)> d_deallocator
std::function< void *(size_t)> d_allocator
int blockAlloc(int level)
BuddyAllocator(BuddyAllocator &&)
void setLevel(int block, int level)
BuddyAllocator()
Empty constructor.
void deallocate(void *p, size_t bytes)
Deallocate memory.