Skip to main content
Pigweed's logo Pigweed
  1. Home
  2. Reference
  3. C/C++
  4. pw::allocator::ForwardingPool Class Reference
Loading...
Searching...
No Matches
pw::allocator::ForwardingPool Class Reference

Overview

A pool that is implemented by forwarding calls to another pool.

This type can be used as a generic base type for forwarding pools that provide additional behavior to another pool. It provides default implementations of the virtual methods from Deallocator and Pool, allowing authors of derived types to avoid boilerplate.

Note
It is an error for a derived type to override any of the methods below with an implementation that calls any of the corresponding public methods. If it does, the public, NVI-style method will dispatch to the derived type's override, leading to an infinite recursion. Instead, use the pool accessor or call this type's implementation methods directly:
class MyPool : public pw::allocator::ForwardingPool {
private:
void* Allocate() override {
// INCORRECT! This will infinitely recurse.
// return pw::allocator::ForwardingPool::Allocate();
// Correct: This dispatches to the wrapped pool.
return pool().Allocate();
}
void Deallocate(void* ptr) override {
// Also correct: This dispatches to the wrapped pool.
}
}
Definition: forwarding_pool.h:55
void DoDeallocate(void *ptr) override
Definition: forwarding_pool.h:110
void * Allocate()
Definition: pool.h:45
Inheritance diagram for pw::allocator::ForwardingPool:
pw::allocator::Pool pw::Deallocator pw::allocator::AsyncPool

Protected Member Functions

constexpr ForwardingPool (const Capabilities &capabilities, Layout layout) noexcept
 
constexpr ForwardingPool (Pool &pool) noexcept
 
constexpr void Init (Pool &pool)
 
constexpr Poolpool ()
 
constexpr const Poolpool () const
 
void * DoAllocate () override
 
void DoDeallocate (void *ptr) override
 
Result< LayoutDoGetInfo (InfoType info_type, const void *ptr) const override
 
- Protected Member Functions inherited from pw::allocator::Pool
constexpr Pool (const Capabilities &capabilities, const Layout &layout)
 
virtual void * DoAllocate ()=0
 
- 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::Deallocator
using Capabilities = allocator::Capabilities
 
using Capability = allocator::Capability
 
using Layout = allocator::Layout
 
- Public Member Functions inherited from pw::allocator::Pool
constexpr const Layoutlayout () const
 
void * Allocate ()
 
template<typename T , int &... kExplicitGuard, typename... Args>
std::enable_if_t<!std::is_array_v< T >, T * > New (Args &&... args)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>>
std::enable_if_t< pw::is_bounded_array_v< T >, ElementType * > New ()
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>>
std::enable_if_t< pw::is_unbounded_array_v< T >, ElementType * > New ()
 
template<typename T , int &... kExplicitGuard, typename... Args>
std::enable_if_t<!std::is_array_v< T >, UniquePtr< T > > MakeUnique (Args &&... args)
 
template<typename T >
std::enable_if_t< pw::is_bounded_array_v< T >, UniquePtr< T > > MakeUnique ()
 
template<typename T >
std::enable_if_t< pw::is_unbounded_array_v< T >, UniquePtr< T > > MakeUnique ()
 
- 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)
 
template<typename ElementType >
void Destroy (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 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>
 

Constructor & Destructor Documentation

◆ ForwardingPool() [1/2]

constexpr pw::allocator::ForwardingPool::ForwardingPool ( const Capabilities capabilities,
Layout  layout 
)
inlineconstexprprotectednoexcept

Creates a forwarding pool without setting its wrapped pool.

This constructor should be used when the forwarding pool needs to be created before the pool being wrapped. The pool must be set using Init before any other method is called. The given capabilities and layout must match those of the pool subsequently provided to Init.

◆ ForwardingPool() [2/2]

constexpr pw::allocator::ForwardingPool::ForwardingPool ( Pool pool)
inlineexplicitconstexprprotectednoexcept

Creates a forwarding pool that wraps a given pool.

This constructor should be used when the forwarding pool is created after the pool being wrapped.

The pool must remain valid for the lifetime of this object.

Member Function Documentation

◆ DoAllocate()

void * pw::allocator::ForwardingPool::DoAllocate ( )
inlineoverrideprotectedvirtual

Returns a chunk of memory with this object's fixed layout.

Like pw::allocator::Allocate, returns null if memory is exhausted.

Return values
Theallocated memory.

Implements pw::allocator::Pool.

◆ DoDeallocate()

void pw::allocator::ForwardingPool::DoDeallocate ( void *  ptr)
inlineoverrideprotectedvirtual

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.

Implements pw::Deallocator.

◆ DoGetInfo()

Result< Layout > pw::allocator::ForwardingPool::DoGetInfo ( InfoType  info_type,
const void *  ptr 
) const
inlineoverrideprotectedvirtual

Returns deallocator-specific information about allocations.

Deallocators may support any number of InfoTypes. See that type for what each supported type returns. For unsupported types, this method returns UNIMPLEMENTED.

Reimplemented from pw::Deallocator.

◆ Init()

constexpr void pw::allocator::ForwardingPool::Init ( Pool pool)
inlineconstexprprotected

Sets the pool being wrapped.

It is an error to call this method if a pool was provided to the constructor. The capabilities of the given pool must match those of previously provided to the constructor.

The pool must remain valid for the lifetime of this object.


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