Advanced Multi-Physics (AMP)
On-Line Documentation
StackAllocator.h
Go to the documentation of this file.
1#ifndef included_StackAllocator
2#define included_StackAllocator
3
4
5#include <cstdint>
6#include <functional>
7#include <stdlib.h>
8
9
18{
19public:
21 explicit StackAllocator( size_t bytes,
22 size_t blockSize = 1024,
23 std::function<void *( size_t )> allocator = ::malloc,
24 std::function<void( void * )> deallocator = ::free );
25
28
31
32 // Copy/assignment constructors
33 StackAllocator( const StackAllocator & ) = delete;
37
39 void *allocate( size_t bytes );
40
42 void deallocate( void *p, size_t bytes );
43
45 static constexpr bool isLIFO() { return true; }
46
47private:
48 // Member data
49 uint8_t d_blockSize; // Blocksize stored as 2^n
50 uint32_t d_available; // Number of blocks availible
51 uint32_t d_N; // Number of current allocations
52 uint32_t d_capacity; // Number of available allocations
53 void *d_memory; // Raw memory pointer
54 void **d_ptr; // Array of pointers allocated
55 std::function<void *( size_t )> d_allocator;
56 std::function<void( void * )> d_deallocator;
57};
58
59
60#endif
~StackAllocator()
Destructor.
uint32_t d_available
uint32_t d_capacity
std::function< void *(size_t)> d_allocator
StackAllocator(const StackAllocator &)=delete
StackAllocator(StackAllocator &&)
StackAllocator & operator=(StackAllocator &&)
StackAllocator(size_t bytes, size_t blockSize=1024, std::function< void *(size_t)> allocator=::malloc, std::function< void(void *)> deallocator=::free)
Default constructor.
StackAllocator & operator=(const StackAllocator &)=delete
StackAllocator()
Empty constructor.
void deallocate(void *p, size_t bytes)
Deallocate memory.
std::function< void(void *)> d_deallocator
static constexpr bool isLIFO()
Check if the allocator is Last-In-First-Out (LIFO)
void * allocate(size_t bytes)
Allocate memory.



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