17 #ifndef TLX_STACK_ALLOCATOR_HEADER 18 #define TLX_STACK_ALLOCATOR_HEADER 31 template <
size_t Size>
74 "StackAllocator has outlived StackArena");
77 if (
buf_ + Size >= ptr_ + n) {
80 if (n % alignment != 0)
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_); }
113 template <
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>
189 #endif // !TLX_STACK_ALLOCATOR_HEADER AlignmentHelper dummy_for_alignment_
enforce alignment
char * ptr_
pointer into free bytes in buf_
static constexpr size_t alignment
StackAllocator() noexcept
default constructor to invalid arena
const Type * const_pointer
bool pointer_in_buffer(char *p) noexcept
debug method to check whether ptr_ is still in buf_.
const Type & const_reference
static bool operator!=(const StringView &a, const std::string &b) noexcept
inequality operator to compare a StringView with a std::string
char * allocate(size_t n)
StackArena< Size > * arena_
Storage area allocated on the stack and usable by a StackAllocator.
size_t used() const noexcept
return number of bytes used in StackArena
std::true_type is_always_equal
C++11 type flag.
StackArena() noexcept
default constructor: free pointer at the beginning.
StackAllocator(const StackAllocator< Other, Size > &other) noexcept
constructor from another allocator with same arena size
std::ptrdiff_t difference_type
pointer allocate(size_t n)
allocate method: get memory from arena
char buf_[Size]
stack memory area used for allocations.
static constexpr size_t size() noexcept
size of memory area
static bool operator==(const StringView &a, const std::string &b) noexcept
equality operator to compare a StringView with a std::string
void deallocate(char *p, size_t n) noexcept
void reset() noexcept
reset memory area
~StackArena()
destructor clears ptr_ for debugging.
StackAllocator(StackArena< Size > &arena) noexcept
constructor with explicit arena reference
union to enforce alignment of buffer area
void deallocate(pointer p, size_t n) noexcept
deallocate method: release from arena
StackArena & operator=(const StackArena &)=delete