Pigweed
C/C++ API Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
pw::multibuf::ChunkRegionTracker Class Referenceabstract
Inheritance diagram for pw::multibuf::ChunkRegionTracker:
pw::multibuf::HeaderChunkRegionTracker pw::multibuf::SingleChunkRegionTracker pw::multibuf::internal::LinkedRegionTracker

Public Member Functions

std::optional< OwnedChunkCreateFirstChunk ()
 

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.
 

Detailed Description

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:

Member Function Documentation

◆ AllocateChunkClass()

virtual void * pw::multibuf::ChunkRegionTracker::AllocateChunkClass ( )
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.

◆ CreateFirstChunk()

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.

◆ DeallocateChunkClass()

virtual void pw::multibuf::ChunkRegionTracker::DeallocateChunkClass ( void *  )
protectedpure virtual

Deallocates a pointer returned by AllocateChunkClass.

Implemented in pw::multibuf::internal::LinkedRegionTracker, pw::multibuf::SingleChunkRegionTracker, and pw::multibuf::HeaderChunkRegionTracker.

◆ Destroy()

virtual void pw::multibuf::ChunkRegionTracker::Destroy ( )
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.

◆ Region()

virtual ByteSpan pw::multibuf::ChunkRegionTracker::Region ( ) const
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.


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