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

#include <StackAllocator.h>

Public Member Functions

void * allocate (size_t bytes)
 Allocate memory.
 
void deallocate (void *p, size_t bytes)
 Deallocate memory.
 
StackAllocatoroperator= (const StackAllocator &)=delete
 
StackAllocatoroperator= (StackAllocator &&)
 
 StackAllocator ()
 Empty constructor.
 
 StackAllocator (const StackAllocator &)=delete
 
 StackAllocator (size_t bytes, size_t blockSize=1024, std::function< void *(size_t)> allocator=::malloc, std::function< void(void *)> deallocator=::free)
 Default constructor.
 
 StackAllocator (StackAllocator &&)
 
 ~StackAllocator ()
 Destructor.
 

Static Public Member Functions

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

Private Attributes

std::function< void *(size_t)> d_allocator
 
uint32_t d_available
 
uint8_t d_blockSize
 
uint32_t d_capacity
 
std::function< void(void *)> d_deallocator
 
void * d_memory
 
uint32_t d_N
 
void ** d_ptr
 

Detailed Description

This class provides basic routines to allocate/deallocate memory. This allocator works like a stack and requires that items are free'd in the reverse order in which they are created. This class is not thread-safe.

Definition at line 17 of file StackAllocator.h.

Constructor & Destructor Documentation

◆ StackAllocator() [1/4]

StackAllocator::StackAllocator ( size_t  bytes,
size_t  blockSize = 1024,
std::function< void *(size_t)>  allocator = ::malloc,
std::function< void(void *)>  deallocator = ::free 
)
explicit

Default constructor.

◆ StackAllocator() [2/4]

StackAllocator::StackAllocator ( )

Empty constructor.

◆ ~StackAllocator()

StackAllocator::~StackAllocator ( )

Destructor.

◆ StackAllocator() [3/4]

StackAllocator::StackAllocator ( const StackAllocator )
delete

◆ StackAllocator() [4/4]

StackAllocator::StackAllocator ( StackAllocator &&  )

Member Function Documentation

◆ allocate()

void * StackAllocator::allocate ( size_t  bytes)

Allocate memory.

◆ deallocate()

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

Deallocate memory.

◆ isLIFO()

static constexpr bool StackAllocator::isLIFO ( )
inlinestaticconstexpr

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

Definition at line 45 of file StackAllocator.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

StackAllocator & StackAllocator::operator= ( StackAllocator &&  )

Member Data Documentation

◆ d_allocator

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

Definition at line 55 of file StackAllocator.h.

◆ d_available

uint32_t StackAllocator::d_available
private

Definition at line 50 of file StackAllocator.h.

◆ d_blockSize

uint8_t StackAllocator::d_blockSize
private

Definition at line 49 of file StackAllocator.h.

◆ d_capacity

uint32_t StackAllocator::d_capacity
private

Definition at line 52 of file StackAllocator.h.

◆ d_deallocator

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

Definition at line 56 of file StackAllocator.h.

◆ d_memory

void* StackAllocator::d_memory
private

Definition at line 53 of file StackAllocator.h.

◆ d_N

uint32_t StackAllocator::d_N
private

Definition at line 51 of file StackAllocator.h.

◆ d_ptr

void** StackAllocator::d_ptr
private

Definition at line 54 of file StackAllocator.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