C/C++ API Reference
Loading...
Searching...
No Matches
pw::multibuf::v1::SingleChunkRegionTracker Class Reference

Overview

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.

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

Public Member Functions

 SingleChunkRegionTracker ()=default
 
 SingleChunkRegionTracker (ByteSpan region)
 
void SetRegion (ByteSpan region)
 
std::optional< OwnedChunkGetChunk (size_t size)
 
void Destroy () override
 
ByteSpan Region () const override
 
void * AllocateChunkClass () override
 
void DeallocateChunkClass (void *chunk) override
 Deallocates a pointer returned by AllocateChunkClass.
 
- Public Member Functions inherited from pw::multibuf::v1::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.
 

Constructor & Destructor Documentation

◆ SingleChunkRegionTracker() [1/2]

pw::multibuf::v1::SingleChunkRegionTracker::SingleChunkRegionTracker ( )
default

Default constructor.

Callers must call SetRegion before calling GetChunk.

◆ SingleChunkRegionTracker() [2/2]

pw::multibuf::v1::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::v1::SingleChunkRegionTracker::AllocateChunkClass ( )
inlineoverridevirtual

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

Implements pw::multibuf::v1::ChunkRegionTracker.

◆ DeallocateChunkClass()

void pw::multibuf::v1::SingleChunkRegionTracker::DeallocateChunkClass ( void *  )
inlineoverridevirtual

Deallocates a pointer returned by AllocateChunkClass.

Implements pw::multibuf::v1::ChunkRegionTracker.

◆ Destroy()

void pw::multibuf::v1::SingleChunkRegionTracker::Destroy ( )
inlineoverridevirtual

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::v1::ChunkRegionTracker.

◆ GetChunk()

std::optional< OwnedChunk > pw::multibuf::v1::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::v1::SingleChunkRegionTracker::Region ( ) const
inlineoverridevirtual

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::v1::ChunkRegionTracker.

◆ SetRegion()

void pw::multibuf::v1::SingleChunkRegionTracker::SetRegion ( ByteSpan  region)
inline

Sets the region used to provide the chunk.

At most one region may be set by this method or a constructor.


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