Pigweed
|
#include <bucket_block_allocator.h>
Public Types | |
using | Base = BlockAllocator< OffsetType, 0, std::max(kAlign, alignof(std::byte *))> |
using | BlockType = typename Base::BlockType |
![]() | |
using | BlockType = Block< OffsetType, kAlign, kPoisonInterval !=0 > |
using | Range = typename BlockType::Range |
![]() | |
using | Capabilities = allocator::Capabilities |
using | Capability = allocator::Capability |
using | Layout = allocator::Layout |
Public Member Functions | |
constexpr | BucketBlockAllocator () |
Constexpr constructor. Callers must explicitly call Init . | |
BucketBlockAllocator (ByteSpan region) | |
void | Init (ByteSpan region) |
void | Init (BlockType *begin) |
void | Init (BlockType *begin, BlockType *end) override |
![]() | |
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 () |
![]() | |
GenericBlockAllocator (const GenericBlockAllocator &)=delete | |
GenericBlockAllocator & | operator= (const GenericBlockAllocator &)=delete |
GenericBlockAllocator (GenericBlockAllocator &&)=delete | |
GenericBlockAllocator & | operator= (GenericBlockAllocator &&)=delete |
![]() | |
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 () |
![]() | |
const Capabilities & | capabilities () 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 constexpr Capabilities | kCapabilities |
![]() | |
using | ReverseRange = typename BlockType::ReverseRange |
![]() | |
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 *) |
![]() | |
constexpr | Allocator ()=default |
TODO(b/326509341): Remove when downstream consumers migrate. | |
constexpr | Allocator (const Capabilities &capabilities) |
![]() | |
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 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. | |
Block allocator that uses sized buckets of free blocks..
In this strategy, the allocator handles an allocation request by starting with the bucket with the smallest size that is larger than the requested size. It tries to allocate using the blocks in that block, if any, before trying the bucket with the next largest size.
On deallocation, blocks are placed in the bucket of the smallest size that is larger than usable space of the block being freed.
The last bucket always has an unbounded size.
As an example, assume that the allocator is configured with a minimum chunk size of 64 and 5 buckets. The internal state may look like the following:
Note that since this allocator stores information in free chunks, it does not currently support poisoning.
|
inlineexplicit |
Non-constexpr constructor that automatically calls Init
.
[in] | region | Region 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 . |
|
inline |
Sets the memory region to be used by this allocator.
This method will instantiate an initial block using the memory region.
[in] | region | Region 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 . |
|
inlineoverridevirtual |
Sets the memory region to be used by this allocator.
This method will instantiate an initial block using the memory region.
[in] | region | Region 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 . |
Reimplemented from pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >.
|
inline |
Sets the memory region to be used by this allocator.
This method will instantiate an initial block using the memory region.
[in] | region | Region 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 . |