Pigweed
 
Loading...
Searching...
No Matches
pw::multibuf::HeaderChunkRegionTracker Class Referencefinal

#include <header_chunk_region_tracker.h>

Inheritance diagram for pw::multibuf::HeaderChunkRegionTracker:
pw::multibuf::ChunkRegionTracker

Public Member Functions

ByteSpan Region () const final
 
- Public Member Functions inherited from pw::multibuf::ChunkRegionTracker
std::optional< OwnedChunkCreateFirstChunk ()
 

Static Public Member Functions

static std::optional< OwnedChunkAllocateRegionAsChunk (allocator::Allocator &alloc, size_t size)
 
static HeaderChunkRegionTrackerAllocateRegion (allocator::Allocator &alloc, size_t size)
 

Protected Member Functions

void Destroy () final
 
void * AllocateChunkClass () final
 
void DeallocateChunkClass (void *ptr) final
 Deallocates a pointer returned by AllocateChunkClass.
 
virtual void Destroy ()=0
 
virtual ByteSpan Region () const =0
 
virtual void * AllocateChunkClass ()=0
 
virtual void DeallocateChunkClass (void *)=0
 Deallocates a pointer returned by AllocateChunkClass.
 

Detailed Description

A ChunkRegionTracker which stores its Chunk and region metadata in a allocator::Allocator allocation alongside the data.

This is useful when testing and when there is no need for asynchronous allocation.

Member Function Documentation

◆ AllocateChunkClass()

void * pw::multibuf::HeaderChunkRegionTracker::AllocateChunkClass ( )
inlinefinalprotectedvirtual

Returns a pointer to sizeof(Chunk) bytes with alignas(Chunk). Returns nullptr on failure.

Implements pw::multibuf::ChunkRegionTracker.

◆ AllocateRegion()

static HeaderChunkRegionTracker * pw::multibuf::HeaderChunkRegionTracker::AllocateRegion ( allocator::Allocator alloc,
size_t  size 
)
inlinestatic

Allocates a new region of size bytes in alloc.

The underlyiing allocation will also store the HeaderChunkRegionTracker itself. The allocated memory must not outlive the provided allocator alloc.

Returns a pointer to the newly-created HeaderChunkRegionTracker or nullptr if the allocation failed.

◆ AllocateRegionAsChunk()

static std::optional< OwnedChunk > pw::multibuf::HeaderChunkRegionTracker::AllocateRegionAsChunk ( allocator::Allocator alloc,
size_t  size 
)
inlinestatic

Allocates a new Chunk region of size bytes in alloc.

The underlyiing allocation will also store the HeaderChunkRegionTracker itself. The allocated memory must not outlive the provided allocator alloc.

Returns the newly-created OwnedChunk if successful.

◆ DeallocateChunkClass()

void pw::multibuf::HeaderChunkRegionTracker::DeallocateChunkClass ( void *  )
inlinefinalprotectedvirtual

Deallocates a pointer returned by AllocateChunkClass.

Implements pw::multibuf::ChunkRegionTracker.

◆ Destroy()

void pw::multibuf::HeaderChunkRegionTracker::Destroy ( )
inlinefinalprotectedvirtual

Destroys the ChunkRegionTracker.

Typical implementations will call std::destroy_at(this) and then free the memory associated with the region and the tracker.

Implements pw::multibuf::ChunkRegionTracker.

◆ Region()

ByteSpan pw::multibuf::HeaderChunkRegionTracker::Region ( ) const
inlinefinalvirtual

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.

Implements pw::multibuf::ChunkRegionTracker.


The documentation for this class was generated from the following file: