cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
cppcore::TStackAllocator< T > Class Template Reference

This class implements a simple stack-based allocation scheme. Initially you have to define its size. Each allocation will be done from this initially created pool and must be deallocated in LIFO order. All data will be released when the allocator will be released. This allocation scheme is fast and does no call any new-calls during the lifetime of the allocator pool. More...

#include <TStackAllocator.h>

Public Member Functions

 TStackAllocator ()=default
 The default class constructor.
 TStackAllocator (size_t initSize)
 The class constructor with the initial size for the stack.
 ~TStackAllocator ()
 The class destructor.
T * alloc (size_t size)
 Will allocate the number of items from the stack.
bool release (T *ptr)
 Will release the last item from the stack.
void reserve (size_t size)
void clear ()
 Will clear the whole memory, all used data will be marked as invalid.
void reset ()
 Will reset the allocated memory, all used data will be marked as invalid.
size_t capacity () const
 Returns the number of allocated instances on the stack.
size_t reservedMem () const
 Returns the allocated memory in bytes.
size_t freeMem () const
 Returns the free memory in bytes.
void dumpAllocations (std::string &allocs)
 Will dump a statistic overview into the given string.

Detailed Description

template<class T>
class cppcore::TStackAllocator< T >

This class implements a simple stack-based allocation scheme. Initially you have to define its size. Each allocation will be done from this initially created pool and must be deallocated in LIFO order. All data will be released when the allocator will be released. This allocation scheme is fast and does no call any new-calls during the lifetime of the allocator pool.

Template Parameters
Typefor the allocation

Definition at line 44 of file TStackAllocator.h.

Constructor & Destructor Documentation

◆ TStackAllocator() [1/2]

template<class T>
cppcore::TStackAllocator< T >::TStackAllocator ( )
default

The default class constructor.

References TStackAllocator().

Referenced by TStackAllocator().

◆ TStackAllocator() [2/2]

template<class T>
cppcore::TStackAllocator< T >::TStackAllocator ( size_t initSize)
inlineexplicit

The class constructor with the initial size for the stack.

Parameters
initSize[in] The initial size.

Definition at line 106 of file TStackAllocator.h.

References reserve().

◆ ~TStackAllocator()

template<class T>
cppcore::TStackAllocator< T >::~TStackAllocator ( )
inline

The class destructor.

Definition at line 111 of file TStackAllocator.h.

References clear().

Member Function Documentation

◆ alloc()

template<class T>
T * cppcore::TStackAllocator< T >::alloc ( size_t size)
inline

Will allocate the number of items from the stack.

Parameters
size[in] The requested size of items.

Definition at line 116 of file TStackAllocator.h.

◆ capacity()

template<class T>
size_t cppcore::TStackAllocator< T >::capacity ( ) const
inline

Returns the number of allocated instances on the stack.

Returns
The number of allocated instance.

Definition at line 185 of file TStackAllocator.h.

◆ clear()

template<class T>
void cppcore::TStackAllocator< T >::clear ( )
inline

Will clear the whole memory, all used data will be marked as invalid.

Definition at line 170 of file TStackAllocator.h.

Referenced by reserve(), and ~TStackAllocator().

◆ dumpAllocations()

template<class T>
void cppcore::TStackAllocator< T >::dumpAllocations ( std::string & allocs)
inline

Will dump a statistic overview into the given string.

Parameters
allocs[inout] The string to hold the allocation statistic.

Definition at line 200 of file TStackAllocator.h.

◆ freeMem()

template<class T>
size_t cppcore::TStackAllocator< T >::freeMem ( ) const
inline

Returns the free memory in bytes.

Returns
The free memory in bytes.

Definition at line 195 of file TStackAllocator.h.

◆ release()

template<class T>
bool cppcore::TStackAllocator< T >::release ( T * ptr)
inline

Will release the last item from the stack.

A basic check will be performed to ensure that it is the correct item.

Parameters
ptr[in] The pointer to validate.

Definition at line 141 of file TStackAllocator.h.

◆ reserve()

template<class T>
void cppcore::TStackAllocator< T >::reserve ( size_t size)
inline

Definition at line 161 of file TStackAllocator.h.

References clear().

Referenced by TStackAllocator().

◆ reservedMem()

template<class T>
size_t cppcore::TStackAllocator< T >::reservedMem ( ) const
inline

Returns the allocated memory in bytes.

Returns
The allocated memory in bytes.

Definition at line 190 of file TStackAllocator.h.

◆ reset()

template<class T>
void cppcore::TStackAllocator< T >::reset ( )
inline

Will reset the allocated memory, all used data will be marked as invalid.

Definition at line 179 of file TStackAllocator.h.


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