Skip to content

Struct ecss::Memory::RetireAllocator

template <class T>

ClassList > ecss > Memory > RetireAllocator

Allocator that defers memory reclamation to avoid use-after-free during container reallocation. More...

  • #include <RetireAllocator.h>

Public Types

Type Name
typedef std::true_type is_always_equal
typedef std::false_type propagate_on_container_move_assignment
typedef T value_type

Public Attributes

Type Name
RetireBin * bin = nullptr

Public Functions

Type Name
RetireAllocator (const RetireAllocator< U > & other) noexcept
RetireAllocator (RetireBin * bin) noexcept
T * allocate (size_t n)
void deallocate (T * p, size_t n) noexcept
bool operator!= (const RetireAllocator< U > & rhs) noexcept const
bool operator== (const RetireAllocator< U > & rhs) noexcept const

Detailed Description

Standard containers like std::vector will call deallocate() on the old buffer immediately after a reallocation. In concurrent scenarios, a reader may still access the old buffer, leading to crashes or undefined behavior. RetireAllocator solves this by not freeing memory right away: deallocate() places the old block into a RetireBin. The user is then responsible for calling RetireBin::drainAll() at a safe point, when no readers can reference retired buffers anymore.

Typical usage: construct a container with a RetireAllocator bound to a shared RetireBin. Push-backs that trigger reallocation will queue the old memory into the bin instead of freeing it. Later, at a known quiescent state, the program calls drainAll() to release all retired memory.

This approach prevents reallocation races from invalidating concurrent readers, at the cost of temporarily higher memory usage until retired blocks are drained.

Public Types Documentation

typedef is_always_equal

using ecss::Memory::RetireAllocator< T >::is_always_equal =  std::true_type;

typedef propagate_on_container_move_assignment

using ecss::Memory::RetireAllocator< T >::propagate_on_container_move_assignment =  std::false_type;

typedef value_type

using ecss::Memory::RetireAllocator< T >::value_type =  T;

Public Attributes Documentation

variable bin

RetireBin* ecss::Memory::RetireAllocator< T >::bin;

Public Functions Documentation

function RetireAllocator [2/3]

template<class U>
inline ecss::Memory::RetireAllocator::RetireAllocator (
    const RetireAllocator < U > & other
) noexcept

function RetireAllocator [3/3]

inline explicit ecss::Memory::RetireAllocator::RetireAllocator (
    RetireBin * bin
) noexcept

function allocate

inline T * ecss::Memory::RetireAllocator::allocate (
    size_t n
) 

function deallocate

inline void ecss::Memory::RetireAllocator::deallocate (
    T * p,
    size_t n
) noexcept

function operator!=

template<class U>
inline bool ecss::Memory::RetireAllocator::operator!= (
    const RetireAllocator < U > & rhs
) noexcept const

function operator==

template<class U>
inline bool ecss::Memory::RetireAllocator::operator== (
    const RetireAllocator < U > & rhs
) noexcept const

Friends Documentation

friend RetireAllocator [1/3]

template<class U>
struct ecss::Memory::RetireAllocator::RetireAllocator (
    RetireAllocator
) 


The documentation for this class was generated from the following file ecss/memory/RetireAllocator.h