Pigweed
|
#include <block_allocator.h>
Public Types | |
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 | 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 |
Protected Types | |
using | ReverseRange = typename BlockType::ReverseRange |
Protected Member Functions | |
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) |
Additional Inherited Members | |
![]() | |
static constexpr Capabilities | kCapabilities |
![]() | |
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. | |
A memory allocator that uses a list of blocks.
This class does not implement ChooseBlock
and cannot be used directly. Instead, use one of its specializations.
NOTE!! Do NOT use memory returned from this allocator as the backing for another allocator. If this is done, the Query
method may incorrectly think pointers returned by that allocator were created by this one, and report that this allocator can de/reallocate them.
|
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 . |
|
protected |
Returns the block associated with a pointer.
If the given pointer is to this allocator's memory region, but not to a valid block, the memory is corrupted and this method will crash to assist in uncovering the underlying bug.
ptr | Pointer to an allocated block's usable space. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: Result contains a pointer to the block. * * OUT_OF_RANGE: Given pointer is outside the allocator's memory. * *
|
inline |
Sets the blocks to be used by this allocator.
This method will use the sequence blocks as-is, which must be valid. The sequence extends to a block marked "last".
[in] | begin | The first block for this allocator. |
|
virtual |
Sets the blocks to be used by this allocator.
This method will use the sequence blocks as-is, which must be valid.
[in] | begin | The first block for this allocator. |
[in] | end | The last block for this allocator. May be null, in which case the sequence ends with the first block marked "last". |
Reimplemented in pw::allocator::BucketBlockAllocator< OffsetType, kMinBucketChunkSize, kNumBuckets, kAlign >.
void pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >::Init | ( | ByteSpan | region | ) |
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 . |
|
protected |
Returns a ReverseRange
of blocks tracking the memory of this allocator.
|
inlineprotectedvirtual |
Indicates that a block is now free.
Does nothing by default. Derived class may overload to do additional bookkeeeping.
block | The block being freed. |
|
inlineprotectedvirtual |
Indicates that a block will no longer be free.
Does nothing by default. Derived class may overload to do additional bookkeeeping.
block | The block being freed. |
void pw::allocator::BlockAllocator< OffsetType, kPoisonInterval, kAlign >::Reset |
Resets the allocator to an uninitialized state.
At the time of the call, there MUST NOT be any outstanding allocated blocks from this allocator.