17#ifndef TLX_STACK_ALLOCATOR_HEADER
18#define TLX_STACK_ALLOCATOR_HEADER
60 {
return buf_ <= p && p <=
buf_ + Size; }
74 "StackAllocator has outlived StackArena");
85 return static_cast<char*
>(malloc(n));
90 "StackAllocator has outlived StackArena");
104 static constexpr size_t size() noexcept {
return Size; }
107 size_t used() const noexcept {
return static_cast<size_t>(
ptr_ -
buf_); }
113template <
typename Type,
size_t Size>
129 template <
typename Other>
140 template <
typename Other>
142 :
arena_(other.arena_) { }
147#if !defined(_MSC_VER)
160 return reinterpret_cast<Type*
>(
arena_->allocate(n *
sizeof(Type)));
165 arena_->deallocate(
reinterpret_cast<char*
>(p), n *
sizeof(Type));
168 template <
typename Other,
size_t OtherSize>
171 return Size == OtherSize &&
arena_ == other.arena_;
174 template <
typename Other,
size_t OtherSize>
180 template <
typename Other,
size_t OtherSize>
StackAllocator(const StackAllocator &) noexcept=default
copy-constructor: default
StackAllocator(StackArena< Size > &arena) noexcept
constructor with explicit arena reference
pointer allocate(size_t n)
allocate method: get memory from arena
StackAllocator & operator=(const StackAllocator &) noexcept=default
copy-assignment: default
const Type * const_pointer
bool operator==(const StackAllocator< Other, OtherSize > &other) const noexcept
StackAllocator() noexcept
default constructor to invalid arena
void deallocate(pointer p, size_t n) noexcept
deallocate method: release from arena
std::false_type is_always_equal
C++11 type flag.
const Type & const_reference
StackArena< Size > * arena_
bool operator!=(const StackAllocator< Other, OtherSize > &other) const noexcept
std::ptrdiff_t difference_type
StackAllocator(const StackAllocator< Other, Size > &other) noexcept
constructor from another allocator with same arena size
StackAllocator(StackAllocator &&) noexcept=default
move-constructor: default
Storage area allocated on the stack and usable by a StackAllocator.
void reset() noexcept
reset memory area
~StackArena()
destructor clears ptr_ for debugging.
StackArena() noexcept
default constructor: free pointer at the beginning.
bool pointer_in_buffer(char *p) noexcept
debug method to check whether ptr_ is still in buf_.
AlignmentHelper dummy_for_alignment_
enforce alignment
StackArena(const StackArena &)=delete
char * ptr_
pointer into free bytes in buf_
void deallocate(char *p, size_t n) noexcept
size_t used() const noexcept
return number of bytes used in StackArena
char * allocate(size_t n)
static constexpr size_t alignment
char buf_[Size]
stack memory area used for allocations.
StackArena & operator=(const StackArena &)=delete
static constexpr size_t size() noexcept
size of memory area
union to enforce alignment of buffer area