C/C++ API Reference
Loading...
Searching...
No Matches
pw::multibuf::v1_adapter::internal::SingleChunkAllocator Class Reference

Overview

Allocator designed to allocate a single chunk at any given time.

This restriction allows the allocator to manage its chunk metadata directly, without relying on the metadata allocator.

Inheritance diagram for pw::multibuf::v1_adapter::internal::SingleChunkAllocator:
pw::multibuf::v1_adapter::internal::ChunkAllocator pw::Allocator pw::Deallocator pw::multibuf::v1_adapter::SingleChunkRegionTracker

Public Member Functions

 SingleChunkAllocator (Allocator &metadata_allocator)
 
void SetRegion (ByteSpan region)
 
- Public Member Functions inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator
constexpr Allocatormetadata_allocator () const
 
constexpr size_t alignment () const
 
constexpr size_t available () const
 
constexpr ByteSpan buffer () const
 
std::optional< OwnedChunkAllocateChunk (size_t min_size, size_t desired_size)
 
std::optional< OwnedChunkAllocateChunk (size_t size)
 
- Public Member Functions inherited from pw::Allocator
void * Allocate (Layout layout)
 
template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args>
T * New (Args &&... args)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_bounded_array_v< T >, int > = 0>
ElementType * New ()
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
ElementType * New (size_t count)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
ElementType * New (size_t count, size_t alignment)
 Constructs an alignment-byte aligned array of count objects.
 
template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args>
UniquePtr< T > MakeUnique (Args &&... args)
 
template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
UniquePtr< T > MakeUnique (size_t size)
 
template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
UniquePtr< T > MakeUnique (size_t size, size_t alignment)
 
template<typename T , std::enable_if_t< is_bounded_array_v< T >, int > = 0>
UniquePtr< T > MakeUnique ()
 
template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0, typename... Args>
SharedPtr< T > MakeShared (Args &&... args)
 
template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
SharedPtr< T > MakeShared (size_t size)
 
template<typename T , std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
SharedPtr< T > MakeShared (size_t size, size_t alignment)
 
template<typename T , std::enable_if_t< is_bounded_array_v< T >, int > = 0>
SharedPtr< T > MakeShared ()
 
bool Resize (void *ptr, size_t new_size)
 
void * Reallocate (void *ptr, Layout new_layout)
 
size_t GetAllocated () const
 
std::optional< FragmentationMeasureFragmentation () const
 Returns fragmentation information for the allocator's memory region.
 
- Public Member Functions inherited from pw::Deallocator
constexpr const Capabilitiescapabilities () const
 
constexpr bool HasCapability (Capability capability) const
 Returns whether a given capability is enabled for this object.
 
void Deallocate (void *ptr)
 
template<typename ElementType >
void DeleteArray (ElementType *ptr, size_t count)
 
StatusWithSize GetCapacity () const
 
bool IsEqual (const Deallocator &other) const
 
template<typename T , int &... kExplicitGuard, std::enable_if_t<!std::is_array_v< T >, int > = 0>
void Delete (T *ptr)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_bounded_array_v< T >, int > = 0>
void Delete (ElementType *ptr)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
void Delete (ElementType *ptr, size_t count)
 

Protected Member Functions

constexpr bool control_block_free () const
 
void DeallocateControlBlock (void *ptr)
 Release the chunk shared pointer metadata.
 
void * DoAllocate (Layout layout) override
 
void DoDeallocate (void *ptr) override
 
Region * AllocateRegion (size_t min_size, size_t desired_size) override
 
size_t TryDeallocateRegion (void *ptr) override
 
virtual void Destroy ()
 
- Protected Member Functions inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator
 PW_PACKED (struct) Region
 
 ChunkAllocator (Allocator &metadata_allocator, size_t alignment)
 
constexpr size_t num_allocations () const
 
void SetRegion (ByteSpan region)
 
void * DoAllocate (allocator::Layout layout) override
 
void DoDeallocate (void *ptr) override
 
Result< LayoutDoGetInfo (InfoType info_type, const void *ptr) const override
 
virtual Region * AllocateRegion (size_t min_size, size_t desired_size)=0
 
virtual size_t TryDeallocateRegion (void *ptr)=0
 
- Protected Member Functions inherited from pw::Allocator
constexpr Allocator ()=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Allocator (const Capabilities &capabilities)
 
virtual void * DoAllocate (Layout layout)=0
 
virtual bool DoResize (void *ptr, size_t new_size)
 
virtual void * DoReallocate (void *ptr, Layout new_layout)
 
virtual size_t DoGetAllocated () const
 
virtual std::optional< FragmentationDoMeasureFragmentation () const
 Returns fragmentation information for the allocator's memory region.
 
- Protected Member Functions inherited from pw::Deallocator
constexpr Deallocator ()=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Deallocator (const Capabilities &capabilities)
 
Result< LayoutGetInfo (InfoType info_type, const void *ptr) const
 
Result< LayoutGetRequestedLayout (const void *ptr) const
 
Result< LayoutGetUsableLayout (const void *ptr) const
 
Result< LayoutGetAllocatedLayout (const void *ptr) const
 
bool Recognizes (const void *ptr) const
 
virtual void DoDeallocate (void *ptr)=0
 
virtual Result< LayoutDoGetInfo (InfoType, const void *) const
 

Additional Inherited Members

- Public Types inherited from pw::Allocator
using Fragmentation = allocator::Fragmentation
 
- Public Types inherited from pw::Deallocator
using Capabilities = allocator::Capabilities
 
using Capability = allocator::Capability
 
using Layout = allocator::Layout
 
- Protected Types inherited from pw::multibuf::v1_adapter::internal::ChunkAllocator
using ControlBlock = allocator::internal::ControlBlock
 
- Protected Types inherited from pw::Deallocator
enum class  InfoType {
  kRequestedLayoutOf , kUsableLayoutOf , kAllocatedLayoutOf , kCapacity ,
  kRecognizes
}
 
- Static Protected Member Functions inherited from pw::Deallocator
static Result< LayoutGetInfo (const Deallocator &deallocator, InfoType info_type, const void *ptr)
 
static Result< LayoutGetRequestedLayout (const Deallocator &deallocator, const void *ptr)
 
static Result< LayoutGetUsableLayout (const Deallocator &deallocator, const void *ptr)
 
static Result< LayoutGetAllocatedLayout (const Deallocator &deallocator, const void *ptr)
 
static bool Recognizes (const Deallocator &deallocator, const void *ptr)
 
- Static Protected Attributes inherited from pw::Deallocator
template<typename T >
static constexpr bool is_bounded_array_v = ::pw::is_bounded_array_v<T>
 
template<typename T >
static constexpr bool is_unbounded_array_v = ::pw::is_unbounded_array_v<T>
 

Member Function Documentation

◆ AllocateRegion()

Region * pw::multibuf::v1_adapter::internal::SingleChunkAllocator::AllocateRegion ( size_t  min_size,
size_t  desired_size 
)
overrideprotectedvirtual

Returns a pointer to a region describing allocated memory of at least min_size and up to desired_size, or null if allocation failed.

Implements pw::multibuf::v1_adapter::internal::ChunkAllocator.

◆ Destroy()

virtual void pw::multibuf::v1_adapter::internal::SingleChunkAllocator::Destroy ( )
inlineprotectedvirtual

Destroys the ChunkRegionTracker.

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

Reimplemented in pw::multibuf::v1_adapter::SingleChunkRegionTracker.

◆ DoAllocate()

void * pw::multibuf::v1_adapter::internal::SingleChunkAllocator::DoAllocate ( Layout  layout)
overrideprotectedvirtual

Allocates a block of memory with the specified size and alignment.

Returns nullptr if the allocation cannot be made, or the layout has a size of 0.

Parameters
[in]layoutDescribes the memory to be allocated.

Reimplemented from pw::multibuf::v1_adapter::internal::ChunkAllocator.

◆ DoDeallocate()

void pw::multibuf::v1_adapter::internal::SingleChunkAllocator::DoDeallocate ( void *  ptr)
overrideprotectedvirtual

Releases a previously-allocated block of memory.

The given pointer must have been previously provided by this memory resource; otherwise the behavior is undefined.

Parameters
[in]ptrPointer to previously-allocated memory.

Reimplemented from pw::multibuf::v1_adapter::internal::ChunkAllocator.

◆ SetRegion()

void pw::multibuf::v1_adapter::internal::ChunkAllocator::SetRegion ( ByteSpan  region)

Sets the region used to provide chunks.

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

◆ TryDeallocateRegion()

size_t pw::multibuf::v1_adapter::internal::SingleChunkAllocator::TryDeallocateRegion ( void *  ptr)
overrideprotectedvirtual

Returns the number of bytes deallocated if the given pointer refers to memory described by a region previously returned by AllocateRegion, or 0 if it does not.

Implements pw::multibuf::v1_adapter::internal::ChunkAllocator.


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