MAGE  v0.171.0
Matthias Advanced Game Engine
mage::DoubleEndedMemoryStack Class Reference

#include <memory_stack.hpp>

Classes

class  HighAllocator
 
class  LowAllocator
 

Public Member Functions

 DoubleEndedMemoryStack (std::size_t size, std::size_t alignment)
 
 DoubleEndedMemoryStack (const DoubleEndedMemoryStack &stack)=delete
 
 DoubleEndedMemoryStack (DoubleEndedMemoryStack &&stack) noexcept
 
 ~DoubleEndedMemoryStack ()
 
DoubleEndedMemoryStackoperator= (const DoubleEndedMemoryStack &stack)=delete
 
DoubleEndedMemoryStackoperator= (DoubleEndedMemoryStack &&stack)=delete
 
std::size_t GetAlignment () const noexcept
 
std::size_t GetSize () const noexcept
 
std::size_t GetUsedSize () const noexcept
 
std::size_t GetUsedLowSize () const noexcept
 
std::size_t GetUsedHighSize () const noexcept
 
std::size_t GetAvailableSize () const noexcept
 
std::uintptr_t GetCurrentLowPtr () const noexcept
 
std::uintptr_t GetCurrentHighPtr () const noexcept
 
void Reset () noexcept
 
void RollBackLow (std::uintptr_t ptr) noexcept
 
void RollBackHigh (std::uintptr_t ptr) noexcept
 
void * AllocLow (std::size_t size) noexcept
 
void * AllocHigh (std::size_t size) noexcept
 
template<typename T >
T * AllocDataLow (std::size_t count=1u, bool initialization=false)
 
template<typename T >
T * AllocDataHigh (std::size_t count=1u, bool initialization=false)
 
template<typename T >
LowAllocator< T > GetLowAllocator () noexcept
 
template<typename T >
HighAllocator< T > GetHighAllocator () noexcept
 

Private Attributes

const std::size_t m_size
 
const std::size_t m_alignment
 
std::uintptr_t m_begin
 
std::uintptr_t m_current_low
 
std::uintptr_t m_current_high
 

Detailed Description

A class of double-ended memory stacks.

Constructor & Destructor Documentation

◆ DoubleEndedMemoryStack() [1/3]

mage::DoubleEndedMemoryStack::DoubleEndedMemoryStack ( std::size_t  size,
std::size_t  alignment 
)
explicit

Constructs a double-ended memory stack with given size.

Parameters
[in]sizeThe size in bytes.
[in]alignmentThe alignment in bytes.
Exceptions
std::bad_allocFailed to allocate the memory.

◆ DoubleEndedMemoryStack() [2/3]

mage::DoubleEndedMemoryStack::DoubleEndedMemoryStack ( const DoubleEndedMemoryStack stack)
delete

Constructs a double-ended memory stack from the given double-ended memory stack.

Parameters
[in]stackA reference to the double-ended memory stack to copy.

◆ DoubleEndedMemoryStack() [3/3]

mage::DoubleEndedMemoryStack::DoubleEndedMemoryStack ( DoubleEndedMemoryStack &&  stack)
defaultnoexcept

Constructs a double-ended memory stack by moving the given double-ended memory stack.

Parameters
[in]stackA reference to the double-ended memory stack to move.

◆ ~DoubleEndedMemoryStack()

mage::DoubleEndedMemoryStack::~DoubleEndedMemoryStack ( )

Destructs this double-ended memory stack.

Member Function Documentation

◆ AllocDataHigh()

template<typename T >
T* mage::DoubleEndedMemoryStack::AllocDataHigh ( std::size_t  count = 1u,
bool  initialization = false 
)

Allocates a block of memory on the high side of this memory stack.

Template Parameters
TThe data type.
Parameters
[in]countThe number of objects of type T to allocate in memory.
[in]initializationFlag indicating whether the objects need to be initialized (i.e. the constructor needs to be called).
Returns
nullptr if the allocation failed.
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment.
Note
The objects will be constructed with their default empty constructor.

◆ AllocDataLow()

template<typename T >
T* mage::DoubleEndedMemoryStack::AllocDataLow ( std::size_t  count = 1u,
bool  initialization = false 
)

Allocates a block of memory on the low side of this memory stack.

Template Parameters
TThe data type.
Parameters
[in]countThe number of objects of type T to allocate in memory.
[in]initializationFlag indicating whether the objects need to be initialized (i.e. the constructor needs to be called).
Returns
nullptr if the allocation failed.
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment.
Note
The objects will be constructed with their default empty constructor.

◆ AllocHigh()

void * mage::DoubleEndedMemoryStack::AllocHigh ( std::size_t  size)
noexcept

Allocates a block of memory of the given size on the high side of this memory stack.

Parameters
[in]sizeThe requested size in bytes to allocate in memory.
Returns
nullptr if the allocation failed.
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment.

◆ AllocLow()

void * mage::DoubleEndedMemoryStack::AllocLow ( std::size_t  size)
noexcept

Allocates a block of memory of the given size on the low side of this memory stack.

Parameters
[in]sizeThe requested size in bytes to allocate in memory.
Returns
nullptr if the allocation failed.
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment.

◆ GetAlignment()

std::size_t mage::DoubleEndedMemoryStack::GetAlignment ( ) const
noexcept

Returns the alignment of this double-ended memory stack.

Returns
The alignment in bytes of this double-ended memory stack.

◆ GetAvailableSize()

std::size_t mage::DoubleEndedMemoryStack::GetAvailableSize ( ) const
noexcept

Returns the available size of this double-ended memory stack.

Returns
The available size in bytes of this double-ended memory stack.

◆ GetCurrentHighPtr()

std::uintptr_t mage::DoubleEndedMemoryStack::GetCurrentHighPtr ( ) const
noexcept

Returns a pointer to the current high position of this double-ended memory stack.

Returns
A pointer to the current high position of this double-ended memory stack.

◆ GetCurrentLowPtr()

std::uintptr_t mage::DoubleEndedMemoryStack::GetCurrentLowPtr ( ) const
noexcept

Returns a pointer to the current low position of this double-ended memory stack.

Returns
A pointer to the current low position of this double-ended memory stack.

◆ GetHighAllocator()

template<typename T >
HighAllocator< T > mage::DoubleEndedMemoryStack::GetHighAllocator ( )
noexcept

Returns a high allocator for this single-ended memory stack.

Template Parameters
TThe data type of the allocator.
Returns
A high allocator for this single-ended memory stack.

◆ GetLowAllocator()

template<typename T >
LowAllocator< T > mage::DoubleEndedMemoryStack::GetLowAllocator ( )
noexcept

Returns a low allocator for this single-ended memory stack.

Template Parameters
TThe data type of the allocator.
Returns
A low allocator for this single-ended memory stack.

◆ GetSize()

std::size_t mage::DoubleEndedMemoryStack::GetSize ( ) const
noexcept

Returns the size (used + available) of this double-ended memory stack.

Returns
The size (used + available) in bytes of this memory stack.

◆ GetUsedHighSize()

std::size_t mage::DoubleEndedMemoryStack::GetUsedHighSize ( ) const
noexcept

Returns the used high size of this double-ended memory stack.

Returns
The used low size in bytes of this double-ended memory stack.

◆ GetUsedLowSize()

std::size_t mage::DoubleEndedMemoryStack::GetUsedLowSize ( ) const
noexcept

Returns the used low size of this double-ended memory stack.

Returns
The used high size in bytes of this double-ended memory stack.

◆ GetUsedSize()

std::size_t mage::DoubleEndedMemoryStack::GetUsedSize ( ) const
noexcept

Returns the used size of this double-ended memory stack.

Returns
The used size in bytes of this double-ended memory stack.

◆ operator=() [1/2]

DoubleEndedMemoryStack& mage::DoubleEndedMemoryStack::operator= ( const DoubleEndedMemoryStack stack)
delete

Copies the given double-ended memory stack to this double-ended memory stack.

Parameters
[in]stackA reference to the double-ended memory stack to copy.
Returns
A reference to the copy of the given double-ended memory stack (i.e. this double-ended memory stack).

◆ operator=() [2/2]

DoubleEndedMemoryStack& mage::DoubleEndedMemoryStack::operator= ( DoubleEndedMemoryStack &&  stack)
delete

Moves the given double-ended memory stack to this double-ended memory stack.

Parameters
[in]stackA reference to the double-ended memory stack to move.
Returns
A reference to the moved double-ended memory stack (i.e. this memory stack).

◆ Reset()

void mage::DoubleEndedMemoryStack::Reset ( )
noexcept

Resets this double-ended memory stack.

The pointer to the current low position of this double-ended memory stack will be reset to the begin position of this double-ended memory stack. The pointer to the current high position of this double-ended memory stack will be reset to the end position of this double-ended memory stack.

◆ RollBackHigh()

void mage::DoubleEndedMemoryStack::RollBackHigh ( std::uintptr_t  ptr)
noexcept

Rolls this double-ended memory stack back to the given high position.

Precondition
The given ptr must be in the range of this memory stack.
Parameters
[in]ptrThe pointer to the requested high position of this memory stack.

◆ RollBackLow()

void mage::DoubleEndedMemoryStack::RollBackLow ( std::uintptr_t  ptr)
noexcept

Rolls this double-ended memory stack back to the given low position.

Precondition
The given ptr must be in the range of this memory stack.
Parameters
[in]ptrThe pointer to the requested low position of this memory stack.

Member Data Documentation

◆ m_alignment

const std::size_t mage::DoubleEndedMemoryStack::m_alignment
private

The alignment in bytes of this double-ended memory stack.

◆ m_begin

std::uintptr_t mage::DoubleEndedMemoryStack::m_begin
private

A pointer to the begin of this double-ended memory stack.

◆ m_current_high

std::uintptr_t mage::DoubleEndedMemoryStack::m_current_high
private

A pointer to the current high position of this double-ended memory stack.

◆ m_current_low

std::uintptr_t mage::DoubleEndedMemoryStack::m_current_low
private

A pointer to the current low position of this double-ended memory stack.

◆ m_size

const std::size_t mage::DoubleEndedMemoryStack::m_size
private

The size in bytes of this double-ended memory stack.