DArenaIterator

Iterator for allocs obtained from a xo::mm::DArena.

Context

_images/ditaa-e19c47c869e31a267f45f45fc1c8c45d0a27e1b5.png
#include <xo/arena/DArenaIterator.hpp>

Class

class DArenaIterator

Representation for alloc iterator over arena.

Map showing an arena allocation:

*
*                    <-------------z1--------------->
*           < guard ><  hz  ><     req_z     >< dz  >< guard >
*
*           +++++++++0000zzzz@@@@@@@@@@@@@@@@@ppppppp+++++++++
*
*                    ^       ^                                ^
*                    header  mem                              header
*                    ^                                        (next alloc)
*                    DArenaIterator::pos_
*
*     guard  [+] guard before+after each allocation, for simple sanitize checks
*    header  [0] alloc header (non-size bits)
*            [z] alloc header (size bits)
*       mem  [@] app-requested memory, including padding [p]
*        dz  [p] padding (to uintptr_t alignment.  req_z+dz recorded in header)
*     free_      DArena::free_ just after guard bytes for last allocation
*
*

Member Variables

group Mm-arenaiterator-instance-vars

Variables

const DArena *arena_ = nullptr

iterator visits allocations from this arena

AllocHeader *pos_ = nullptr

current iterator position

Constructors

group DArenaIterator instance vars

Functions

DArenaIterator() = default
inline DArenaIterator(const DArena *arena, AllocHeader *pos)
static inline DArenaIterator invalid()

Create iterator in invalid state

static DArenaIterator begin(const DArena *arena)

Create iterator pointing to the beginning of arena Iterator cannot modify memory, but can capture an iterator error in *arena

static DArenaIterator end(const DArena *arena)

Create iterator pointing to the end of arena Iterator cannot modify memory, but can capture an iterator error in *arena

Methods

group DArenaIterator methods

Functions

static AllocHeader *begin_header(const DArena *arena)

Address of allocation header for beginning of alloc range in arena

static AllocHeader *end_header(const DArena *arena)

Address of allocation header for end of alloc range. This is the address of header for next allocation in arena i.e. free pointer

inline bool is_valid() const noexcept

A valid iterator can be compared, at least with itself It can be dereferenced if is also non-empty

inline bool is_invalid() const noexcept

An invalid (or sentinel) iterator is incomparable with all iterators including itself

AllocInfo deref() const noexcept

fetch contents at current iterator position

cmpresult compare(const DArenaIterator &other) const noexcept

compare two iterators. To be comparable, iterators must refer to the same arena

void next() noexcept

advance iterator to next allocation

inline std::byte *pos_as_byte() const

cast iterator position to byte*

inline AllocInfo operator*() const noexcept

*ix synonym for ix.deref()

inline DArenaIterator &operator++() noexcept

++ix synonym for ix.next()