Pigweed
|
#include <bucket.h>
Classes | |
struct | Chunk |
Public Member Functions | |
Bucket () | |
Constructs a bucket with an unbounded chunk size. | |
Bucket (size_t chunk_size) | |
Bucket (const Bucket &other)=delete | |
Bucket & | operator= (const Bucket &other)=delete |
Bucket (Bucket &&other) | |
Bucket & | operator= (Bucket &&other) |
void | Init (size_t chunk_size=std::numeric_limits< size_t >::max()) |
size_t | chunk_size () const |
bool | empty () const |
size_t | count () const |
void | Add (std::byte *ptr) |
void | Visit (const Function< void(const std::byte *)> &visitor) const |
Applies the given function to each chunk in the bucket. | |
std::byte * | Remove () |
std::byte * | RemoveIf (const Function< bool(const std::byte *)> &cond) |
Static Public Member Functions | |
static void | Init (span< Bucket > buckets, size_t min_chunk_size) |
Creates a list of buckets, with each twice as large as the one before it. | |
static std::byte * | Remove (std::byte *ptr) |
Doubly linked list of free memory regions, or "chunks", of a maximum size or less.
|
explicit |
Construct a bucket.
chunk_size | The maximum size of the memory chunks in this bucket. Must be at least sizeof(Chunk) . |
void pw::allocator::internal::Bucket::Add | ( | std::byte * | ptr | ) |
Adds a memory region to this bucket.
ptr | The memory region to be added. |
size_t pw::allocator::internal::Bucket::count | ( | ) | const |
Returns the number of the chunks in the bucket.
Note: This method runs in O(n) time.
std::byte * pw::allocator::internal::Bucket::Remove | ( | ) |
Removes a chunk from this bucket.
The | removed region, or null if the bucket is empty. |
|
static |
Removes a chunk from any bucket it is a part of.
The | removed region, for convenience. |
ptr | The memory region to be removed. |
std::byte * pw::allocator::internal::Bucket::RemoveIf | ( | const Function< bool(const std::byte *)> & | cond | ) |
Removes a chunk for which a given condition is met.
This will remove at most one chunk.
The | first chunk for which the condition evaluates to true, null if the bucket does not contain any such chunk. |
cond | The condition to be tested on the chunks in this bucket. |