Pigweed
 
Loading...
Searching...
No Matches
pw::allocator::ContiguousBlock< Derived > Class Template Reference

#include <contiguous.h>

Inheritance diagram for pw::allocator::ContiguousBlock< Derived >:
pw::allocator::internal::ContiguousBase

Public Member Functions

constexpr Derived * Prev () const
 
constexpr Derived * Next () const
 

Protected Member Functions

constexpr Derived * DoSplitFirst (size_t new_inner_size)
 
constexpr Derived * DoSplitLast (size_t new_inner_size)
 
constexpr void DoMergeNext ()
 
constexpr bool DoCheckInvariants (bool strict) const
 Performs the ContiguousBlock invariant checks.
 

Friends

template<typename >
class PoisonableBlock
 

Detailed Description

template<typename Derived>
class pw::allocator::ContiguousBlock< Derived >

Mix-in for blocks that collectively represent a contiguous region of memory.

Contiguous blocks can be split into smaller blocks and merged when adjacent.

Block mix-ins are stateless and trivially constructible. See BasicBlock for details on how mix-ins can be combined to implement blocks.

This mix-in requires its derived type also derive from BasicBlock, and provide the following symbols:

  • size_t PrevOuterSizeUnchecked() const
    • Returns the outer size of the previous block, if any, or zero. Must be multiple of kAlignment.
  • bool IsLastUnchecked() const
    • Returns whether this block is the last block.

Member Function Documentation

◆ DoMergeNext()

template<typename Derived >
constexpr void pw::allocator::ContiguousBlock< Derived >::DoMergeNext
constexprprotected

Merges this block with next block.

This method is static in order to consume and replace the given block pointer with a pointer to the new, larger block.

Precondition
The blocks must not be in use.

◆ DoSplitFirst()

template<typename Derived >
constexpr Derived * pw::allocator::ContiguousBlock< Derived >::DoSplitFirst ( size_t  new_inner_size)
constexprprotected

Split a block into two smaller blocks.

This method splits a block into a leading block of the given new_inner_size and a trailing block, and returns the trailing space as a new block.

Precondition
The block must not be in use.
The block must have enough usable space for the requested size.
The space remaining after a split can hold a new block.

◆ DoSplitLast()

template<typename Derived >
constexpr Derived * pw::allocator::ContiguousBlock< Derived >::DoSplitLast ( size_t  new_inner_size)
constexprprotected

Split a block into two smaller blocks.

This method splits a block into a leading block and a trailing block of the given new_inner_size, and returns the trailing space is returned as a new block.

Precondition
The block must not be in use.
The block must have enough usable space for the requested size.
The space remaining after a split can hold a new block.

◆ Next()

template<typename Derived >
constexpr Derived * pw::allocator::ContiguousBlock< Derived >::Next
constexpr
Returns
the block immediately after this one, or null if this is the last block.

◆ Prev()

template<typename Derived >
constexpr Derived * pw::allocator::ContiguousBlock< Derived >::Prev
constexpr
Returns
the block immediately before this one, or null if this is the first block.

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