#include <chunk.h>
Public Member Functions | |
std::optional< OwnedChunk > | CreateFirstChunk () |
Protected Member Functions | |
virtual void | Destroy ()=0 |
virtual ByteSpan | Region () const =0 |
virtual void * | AllocateChunkClass ()=0 |
virtual void | DeallocateChunkClass (void *)=0 |
Deallocates a pointer returned by AllocateChunkClass . | |
An object that manages a single allocated region which is referenced by one or more Chunk
objects.
This class is typically implemented by MultiBufAllocator
implementations in order to customize the behavior of region deallocation.
ChunkRegionTracker
s have three responsibilities:
Chunk
s can expand. This is reported via the Region
method. Chunk
s in this region can refer to memory within this region sparsely, but they can grow or shrink so long as they stay within the bounds of the Region
.ChunkRegionTracker
itself. This is implemented via the Destroy
method, which is called once all of the Chunk
s in a region have been released.Chunk
classes. This is merely allocating space for the Chunk
object itself, not the memory to which it refers. This can be implemented straightforwardly by delegating to an existing generic allocator such as malloc
or a pw::allocator::Allocator
implementation.
|
protectedpure virtual |
Returns a pointer to sizeof(Chunk)
bytes with alignas(Chunk)
. Returns nullptr
on failure.
Implemented in pw::multibuf::HeaderChunkRegionTracker, pw::multibuf::internal::LinkedRegionTracker, and pw::multibuf::SingleChunkRegionTracker.
std::optional< OwnedChunk > pw::multibuf::ChunkRegionTracker::CreateFirstChunk | ( | ) |
Creates the first Chunk
referencing a whole region of memory.
This must only be called once per ChunkRegionTracker
, when the region is first created. Multiple calls will result in undefined behavior.
Returns std::nullopt
if AllocateChunkStorage
returns nullptr
.
|
protectedpure virtual |
Deallocates a pointer returned by AllocateChunkClass
.
Implemented in pw::multibuf::internal::LinkedRegionTracker, pw::multibuf::SingleChunkRegionTracker, and pw::multibuf::HeaderChunkRegionTracker.
|
protectedpure virtual |
Destroys the ChunkRegionTracker
.
Typical implementations will call std::destroy_at(this)
and then free the memory associated with the region and the tracker.
Implemented in pw::multibuf::HeaderChunkRegionTracker, pw::multibuf::internal::LinkedRegionTracker, and pw::multibuf::SingleChunkRegionTracker.
|
protectedpure virtual |
Returns the entire span of the region being managed.
Chunk
s referencing this tracker will not expand beyond this region, nor into one another's portions of the region.
This region does not provide any alignment guarantees by default.
This region must not change for the lifetime of this ChunkRegionTracker
.
Implemented in pw::multibuf::HeaderChunkRegionTracker, pw::multibuf::internal::LinkedRegionTracker, and pw::multibuf::SingleChunkRegionTracker.