Pigweed
 
Loading...
Searching...
No Matches
pw::allocator::internal::BuddyBlock Class Reference

#include <buddy_allocator.h>

Inheritance diagram for pw::allocator::internal::BuddyBlock:
pw::allocator::BasicBlock< BuddyBlock > pw::allocator::internal::BasicBase

Public Member Functions

 BuddyBlock (size_t outer_size)
 
StatusWithSize CanAlloc (Layout layout) const
 
BuddyBlockSplit ()
 Splits a block in half and returns the new block.
 
- Public Member Functions inherited from pw::allocator::BasicBlock< BuddyBlock >
 BasicBlock (const BasicBlock &other)=delete
 
BasicBlockoperator= (const BasicBlock &other)=delete
 
constexpr std::byte * UsableSpace ()
 
constexpr const std::byte * UsableSpace () const
 
constexpr std::byte * UsableSpaceUnchecked ()
 
constexpr const std::byte * UsableSpaceUnchecked () const
 
constexpr size_t OuterSize () const
 
constexpr size_t InnerSize () const
 
constexpr size_t InnerSizeUnchecked () const
 
constexpr bool IsValid () const
 
constexpr bool CheckInvariants () const
 Like IsValid, but crashes if invalid.
 

Static Public Member Functions

static BuddyBlockMerge (BuddyBlock *&&left, BuddyBlock *&&right)
 Merges two blocks together.
 
- Static Public Member Functions inherited from pw::allocator::BasicBlock< BuddyBlock >
static constexpr Result< BuddyBlock * > Init (ByteSpan region)
 Creates the first block for a given memory region.
 
static constexpr internal::copy_const_ptr_t< Ptr, BuddyBlock * > FromUsableSpace (Ptr usable_space)
 
static constexpr size_t OuterSizeFromInnerSize (size_t inner_size)
 
static constexpr size_t InnerSizeFromOuterSize (size_t outer_size)
 

Additional Inherited Members

- Static Public Attributes inherited from pw::allocator::BasicBlock< BuddyBlock >
static constexpr size_t kAlignment
 
static constexpr size_t kBlockOverhead
 
static constexpr size_t kMinOuterSize
 
- Protected Member Functions inherited from pw::allocator::BasicBlock< BuddyBlock >
constexpr bool DoCheckInvariants (bool strict) const
 

Detailed Description

A specialized block used by the BuddyAllocator.

Buddy blocks have outer sizes that are powers of two. When smaller blocks are needed, a block is split into left and right halves of equal size. These half-blocks are "buddies", and when both are freed they are merged back into a single block.

Member Function Documentation

◆ CanAlloc()

StatusWithSize pw::allocator::internal::BuddyBlock::CanAlloc ( Layout  layout) const

Simplified version of Allocatable::CanAlloc, as needed for UnorderedBucket::Remove.


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