Pigweed
 
Loading...
Searching...
No Matches
pw::multibuf::SingleChunkRegionTracker Class Reference

#include <single_chunk_region_tracker.h>

Inheritance diagram for pw::multibuf::SingleChunkRegionTracker:
pw::multibuf::ChunkRegionTracker

Public Member Functions

 SingleChunkRegionTracker (ByteSpan region)
 
std::optional< OwnedChunkGetChunk (size_t size)
 
void Destroy () final
 
ByteSpan Region () const final
 
void * AllocateChunkClass () final
 
void DeallocateChunkClass (void *chunk) final
 Deallocates a pointer returned by AllocateChunkClass.
 
- Public Member Functions inherited from pw::multibuf::ChunkRegionTracker
std::optional< OwnedChunkCreateFirstChunk ()
 

Additional Inherited Members

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 that uses inline memory to create a single Chunk with the only caveat that the provided Chunk cannot be split. All attempts will result in std::nullopt.

Constructor & Destructor Documentation

◆ SingleChunkRegionTracker()

pw::multibuf::SingleChunkRegionTracker::SingleChunkRegionTracker ( ByteSpan  region)
inlineexplicit

Constructs a region tracker with a single Chunk that maps to region, which must outlive this tracker and any OwnedChunk it creates.

Member Function Documentation

◆ AllocateChunkClass()

void * pw::multibuf::SingleChunkRegionTracker::AllocateChunkClass ( )
inlinefinalvirtual

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

Implements pw::multibuf::ChunkRegionTracker.

◆ DeallocateChunkClass()

void pw::multibuf::SingleChunkRegionTracker::DeallocateChunkClass ( void *  )
inlinefinalvirtual

Deallocates a pointer returned by AllocateChunkClass.

Implements pw::multibuf::ChunkRegionTracker.

◆ Destroy()

void pw::multibuf::SingleChunkRegionTracker::Destroy ( )
inlinefinalvirtual

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.

◆ GetChunk()

std::optional< OwnedChunk > pw::multibuf::SingleChunkRegionTracker::GetChunk ( size_t  size)
inline

Gets a Chunk of a given size, which must be less than or equal to the provided region.

Returns: An OwnedChunk if the Chunk is free, otherwise std::nullopt, in which case GetChunk() can be called again.

◆ Region()

ByteSpan pw::multibuf::SingleChunkRegionTracker::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: