Advanced Multi-Physics (AMP)
On-Line Documentation
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
BuddyAllocator Class Reference

#include <BuddyAllocator.h>

Public Member Functions

void * allocate (size_t bytes)
 Allocate memory.
 
 BuddyAllocator ()
 Empty constructor.
 
 BuddyAllocator (BuddyAllocator &&)
 
 BuddyAllocator (const BuddyAllocator &)=delete
 
 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.
 
void deallocate (void *p, size_t bytes)
 Deallocate memory.
 
BuddyAllocatoroperator= (BuddyAllocator &&)
 
BuddyAllocatoroperator= (const BuddyAllocator &)=delete
 
 ~BuddyAllocator ()
 Destructor.
 

Static Public Member Functions

static constexpr bool isLIFO ()
 Check if the allocator is Last-In-First-Out (LIFO)
 

Private Member Functions

void allocateSize ()
 
int blockAlloc (int level)
 
void blockFree (int level, int block)
 
int getLevel (int block)
 
size_t N_blocks () const
 
size_t N_bytes () const
 
void setLevel (int block, int level)
 

Private Attributes

std::function< void *(size_t)> d_allocator
 
std::function< void(void *)> d_deallocator
 
uint8_t d_log_N
 
void * d_memory
 
uint8_t d_n
 
int * d_N
 
int * d_ptr
 
int8_t * d_size
 
std::function< void(void *, size_t)> d_zero
 

Detailed Description

This class provides basic routines to allocate/deallocate memory

Definition at line 14 of file BuddyAllocator.h.

Constructor & Destructor Documentation

◆ BuddyAllocator() [1/4]

BuddyAllocator::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) {} 
)
explicit

Default constructor.

◆ BuddyAllocator() [2/4]

BuddyAllocator::BuddyAllocator ( )

Empty constructor.

◆ ~BuddyAllocator()

BuddyAllocator::~BuddyAllocator ( )

Destructor.

◆ BuddyAllocator() [3/4]

BuddyAllocator::BuddyAllocator ( const BuddyAllocator )
delete

◆ BuddyAllocator() [4/4]

BuddyAllocator::BuddyAllocator ( BuddyAllocator &&  )

Member Function Documentation

◆ allocate()

void * BuddyAllocator::allocate ( size_t  bytes)

Allocate memory.

◆ allocateSize()

void BuddyAllocator::allocateSize ( )
inlineprivate

Definition at line 53 of file BuddyAllocator.h.

References d_size, and N_blocks().

◆ blockAlloc()

int BuddyAllocator::blockAlloc ( int  level)
private

◆ blockFree()

void BuddyAllocator::blockFree ( int  level,
int  block 
)
private

◆ deallocate()

void BuddyAllocator::deallocate ( void *  p,
size_t  bytes 
)

Deallocate memory.

◆ getLevel()

int BuddyAllocator::getLevel ( int  block)
inlineprivate

Definition at line 55 of file BuddyAllocator.h.

References d_size.

◆ isLIFO()

static constexpr bool BuddyAllocator::isLIFO ( )
inlinestaticconstexpr

Check if the allocator is Last-In-First-Out (LIFO)

Definition at line 44 of file BuddyAllocator.h.

◆ N_blocks()

size_t BuddyAllocator::N_blocks ( ) const
inlineprivate

Definition at line 69 of file BuddyAllocator.h.

References d_n.

Referenced by allocateSize().

◆ N_bytes()

size_t BuddyAllocator::N_bytes ( ) const
inlineprivate

Definition at line 70 of file BuddyAllocator.h.

References d_log_N, and d_n.

◆ operator=() [1/2]

BuddyAllocator & BuddyAllocator::operator= ( BuddyAllocator &&  )

◆ operator=() [2/2]

BuddyAllocator & BuddyAllocator::operator= ( const BuddyAllocator )
delete

◆ setLevel()

void BuddyAllocator::setLevel ( int  block,
int  level 
)
inlineprivate

Definition at line 54 of file BuddyAllocator.h.

References d_size.

Member Data Documentation

◆ d_allocator

std::function<void *( size_t )> BuddyAllocator::d_allocator
private

Definition at line 64 of file BuddyAllocator.h.

◆ d_deallocator

std::function<void( void * )> BuddyAllocator::d_deallocator
private

Definition at line 65 of file BuddyAllocator.h.

◆ d_log_N

uint8_t BuddyAllocator::d_log_N
private

Definition at line 48 of file BuddyAllocator.h.

Referenced by N_bytes().

◆ d_memory

void* BuddyAllocator::d_memory
private

Definition at line 49 of file BuddyAllocator.h.

◆ d_n

uint8_t BuddyAllocator::d_n
private

Definition at line 47 of file BuddyAllocator.h.

Referenced by N_blocks(), and N_bytes().

◆ d_N

int* BuddyAllocator::d_N
private

Definition at line 58 of file BuddyAllocator.h.

◆ d_ptr

int* BuddyAllocator::d_ptr
private

Definition at line 59 of file BuddyAllocator.h.

◆ d_size

int8_t* BuddyAllocator::d_size
private

Definition at line 52 of file BuddyAllocator.h.

Referenced by allocateSize(), getLevel(), and setLevel().

◆ d_zero

std::function<void( void *, size_t )> BuddyAllocator::d_zero
private

Definition at line 66 of file BuddyAllocator.h.


The documentation for this class was generated from the following file:



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page