template<typename Derived, typename BlockType_, typename ItemType_>
class pw::allocator::internal::BucketBase< Derived, BlockType_, ItemType_ >
A container of free blocks.
Allocators can use buckets to manage their free blocks. This may include using buckets to sort free blocks based on their size, partitioning them into several buckets, etc., for faster searching when allocating. Each bucket may have a maximum block inner size set which indicates the largest free block allowable in the bucket, or be unbounded.
This class is a CRTP-style base class. The specific derived class includes an intrusive container type from pw_containers
. The usable space of free blocks added to the bucket is used to store the intrusive item corresponding to the container.
This implies that a block must be large enough to hold the item type in order to be added to a bucket. Since intrusive items can be part of at most one container at any point in time, free blocks can be in at most ONE bucket at any time. However, a sufficiently large block may be sequentially added to more than one type of bucket. This can be useful for allocators that may track blocks in more than one way, e.g. an allocator that caches recently freed blocks.
- Template Parameters
-
Derived | Bucket type derived from this base class. |
BlockType | Type of free blocks that can be held in this bucket. |
ItemType | Intrusive pw_containers type. The usable space of each free block in the bucket will hold an item of this type. |
|
template<typename Iterator , typename Predicate > |
static Iterator | FindPrevIf (Iterator before_first, Iterator last, Predicate predicate) |
|
static auto | MakeCanAllocPredicate (Layout layout) |
|
static bool | Compare (const ItemType &item1, const ItemType &item2) |
|
template<typename Iterator > |
static constexpr BlockType * | GetBlockFromIterator (Iterator iter, Iterator last) |
|
template<typename Iterator > |
static constexpr BlockType * | GetBlockFromPrev (Iterator prev, Iterator last) |
|
static ItemType & | GetItemFrom (BlockType &block) |
|
template<typename Derived , typename BlockType_ , typename ItemType_ >
template<typename Iterator , typename Predicate >
Returns an iterator the first element in a range whose successor satisfies a given predicate
.
The returned iterator will be in the range [before_first
, last
), and will be the element before the first element that satisfies the predicate.
This is intended to act similar to std::find_if
in order to return iterators that can be used with sorted forward lists like std::forward_list<T>
or pw::IntrusiveForwardList<T>. In particular, methods like
insert_afterand
erase_after` need the iterator that precedes a desired item.