Pigweed
 
Loading...
Searching...
No Matches
pw::multibuf::ChunkRegionTracker Class Referenceabstract

#include <chunk.h>

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:

  • Tracking the region of memory into which 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.
  • Deallocating the region and the ChunkRegionTracker itself. This is implemented via the Destroy method, which is called once all of the Chunk s in a region have been released.
  • Allocating and deallocating space for 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.

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: