Pigweed
Loading...
Searching...
No Matches
pw::allocator::DualFirstFitBlockAllocator< OffsetType, kPoisonInterval, kAlign > Class Template Reference

#include <dual_first_fit_block_allocator.h>

Public Types

using Base = BlockAllocator< OffsetType, kPoisonInterval, kAlign >
 
using BlockType = typename Base::BlockType
 
- Public Types inherited from pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >
using BlockType = Block< OffsetType, kAlign, kPoisonInterval !=0 >
 
using Range = typename BlockType::Range
 
- Public Types inherited from pw::Deallocator
using Capabilities = allocator::Capabilities
 
using Capability = allocator::Capability
 
using Layout = allocator::Layout
 

Public Member Functions

constexpr DualFirstFitBlockAllocator ()
 Constexpr constructor. Callers must explicitly call Init.
 
 DualFirstFitBlockAllocator (ByteSpan region, size_t threshold)
 
void set_threshold (size_t threshold)
 Sets the threshold value for which requests are considered "large".
 
- Public Member Functions inherited from pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >
constexpr BlockAllocator ()
 Constexpr constructor. Callers must explicitly call Init.
 
 BlockAllocator (ByteSpan region)
 
Range blocks () const
 Returns a Range of blocks tracking the memory of this allocator.
 
void Init (ByteSpan region)
 
void Init (BlockType *begin)
 
virtual void Init (BlockType *begin, BlockType *end)
 
Fragmentation MeasureFragmentation () const
 Returns fragmentation information for the block allocator's memory region.
 
void Reset ()
 
- Public Member Functions inherited from pw::allocator::internal::GenericBlockAllocator
 GenericBlockAllocator (const GenericBlockAllocator &)=delete
 
GenericBlockAllocatoroperator= (const GenericBlockAllocator &)=delete
 
 GenericBlockAllocator (GenericBlockAllocator &&)=delete
 
GenericBlockAllocatoroperator= (GenericBlockAllocator &&)=delete
 
- Public Member Functions inherited from pw::Allocator
void * Allocate (Layout layout)
 
template<typename T , int &... ExplicitGuard, typename... Args>
T * New (Args &&... args)
 
template<typename T , int &... ExplicitGuard, typename... Args>
UniquePtr< T > MakeUnique (Args &&... args)
 
bool Resize (void *ptr, size_t new_size)
 
bool Resize (void *ptr, Layout layout, size_t new_size)
 
void * Reallocate (void *ptr, Layout new_layout)
 
void * Reallocate (void *ptr, Layout old_layout, size_t new_size)
 
allocator::AsPmrAllocator as_pmr ()
 
- Public Member Functions inherited from pw::Deallocator
const Capabilitiescapabilities () const
 
bool HasCapability (Capability capability) const
 Returns whether a given capabilityis enabled for this object.
 
void Deallocate (void *ptr)
 
void Deallocate (void *ptr, Layout layout)
 
template<typename T >
void Delete (T *ptr)
 
StatusWithSize GetCapacity () const
 
bool IsEqual (const Deallocator &other) const
 

Additional Inherited Members

- Static Public Attributes inherited from pw::allocator::internal::GenericBlockAllocator
static constexpr Capabilities kCapabilities
 
- Protected Types inherited from pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >
using ReverseRange = typename BlockType::ReverseRange
 
- Protected Member Functions inherited from pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >
ReverseRange rblocks ()
 
template<typename PtrType , typename BlockPtrType = std::conditional_t< std::is_const_v<std::remove_pointer_t<PtrType>>, const BlockType*, BlockType*>>
Result< BlockPtrType > FromUsableSpace (PtrType ptr) const
 
virtual void ReserveBlock (BlockType *)
 
virtual void RecycleBlock (BlockType *)
 
- Protected Member Functions inherited from pw::Allocator
constexpr Allocator ()=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Allocator (const Capabilities &capabilities)
 
- Protected Member Functions inherited from pw::Deallocator
constexpr Deallocator ()=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Deallocator (const Capabilities &capabilities)
 
template<typename T >
UniquePtr< T > WrapUnique (T *ptr)
 
- Static Protected Member Functions inherited from pw::allocator::internal::GenericBlockAllocator
static void CrashOnAllocated (void *allocated)
 
static void CrashOnInvalidFree (void *freed)
 
static void CrashOnDoubleFree (void *freed)
 Crashes with an informational message that a given block was freed twice.
 

Detailed Description

template<typename OffsetType = uintptr_t, size_t kPoisonInterval = 0, size_t kAlign = alignof(OffsetType)>
class pw::allocator::DualFirstFitBlockAllocator< OffsetType, kPoisonInterval, kAlign >

Block allocator that uses a "dual first-fit" allocation strategy split between large and small allocations.

In this strategy, the strategy includes a threshold value. Requests for more than this threshold are handled similarly to FirstFit, while requests for less than this threshold are handled similarly to LastFit.

This algorithm approaches the performance of FirstFit and LastFit while improving on those algorithms fragmentation.

Constructor & Destructor Documentation

◆ DualFirstFitBlockAllocator()

template<typename OffsetType = uintptr_t, size_t kPoisonInterval = 0, size_t kAlign = alignof(OffsetType)>
pw::allocator::DualFirstFitBlockAllocator< OffsetType, kPoisonInterval, kAlign >::DualFirstFitBlockAllocator ( ByteSpan  region,
size_t  threshold 
)
inline

Non-constexpr constructor that automatically calls Init.

Parameters
[in]regionRegion of memory to use when satisfying allocation requests. The region MUST be large enough to fit an aligned block with overhead. It MUST NOT be larger than what is addressable by OffsetType.

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