Skip to main content
Pigweed's logo Pigweed
  1. Home
  2. Reference
  3. C/C++
  4. pw_allocator
  5. Forwarding allocators
Loading...
Searching...
No Matches
Forwarding allocators

Overview

Allocator implementations that don’t allocate memory directly and instead rely on other allocators while providing additional behaviors.

Learn more: Forwarding allocator concept

Classes

class  pw::allocator::AllocatorAsPool
 Implementation of Pool that satisfies requests using an Allocator. More...
 
class  pw::allocator::FallbackAllocator
 
class  pw::allocator::GuardedAllocator< BlockAllocatorType, LockType >
 
class  pw::allocator::PmrAllocator
 
class  pw::allocator::SynchronizedAllocator< LockType >
 
struct  pw::allocator::AddTrackingAllocatorAsChild
 
class  pw::allocator::TrackingAllocator< MetricsType >
 

Typedefs

using pw::allocator::NoSync = pw::sync::NoLock
 

Functions

void * pw::allocator::TrackingAllocator< MetricsType >::DoAllocate (Layout layout) override
 
void pw::allocator::TrackingAllocator< MetricsType >::DoDeallocate (void *ptr) override
 
bool pw::allocator::TrackingAllocator< MetricsType >::DoResize (void *ptr, size_t new_size) override
 
void pw::allocator::TrackingAllocator< MetricsType >::DoBeforeReallocate (void *ptr, Layout new_layout) override
 
void pw::allocator::TrackingAllocator< MetricsType >::DoAfterReallocateDone (Layout new_layout, void *new_ptr) override
 

Variables

static constexpr struct pw::allocator::AddTrackingAllocatorAsChild pw::allocator::kAddTrackingAllocatorAsChild = {}
 

Typedef Documentation

◆ NoSync

Tag type used to indicate synchronization is NOT desired.

This can be useful with allocator parameters for module configuration, e.g. PW_MALLOC_LOCK_TYPE.

Function Documentation

◆ DoAfterReallocateDone()

template<typename MetricsType >
void pw::allocator::TrackingAllocator< MetricsType >::DoAfterReallocateDone ( Layout  new_layout,
void *  new_ptr 
)
overrideprivatevirtual

Called as part of the default implementation of DoReallocate just before returning.

By default, does nothing. Derived types may implement this method to add additional behavior. If they do, they must call DoAfterReallocateDone on their base type before performing any other action.

new_ptr is guaranteed to be non-null, and new_layout.size() is guaranteed to be non-zero.

Reimplemented from pw::allocator::ForwardingAllocator.

◆ DoAllocate()

template<typename MetricsType >
void * pw::allocator::TrackingAllocator< MetricsType >::DoAllocate ( Layout  layout)
overrideprivatevirtual

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::allocator::ForwardingAllocator.

◆ DoBeforeReallocate()

template<typename MetricsType >
void pw::allocator::TrackingAllocator< MetricsType >::DoBeforeReallocate ( void *  ptr,
Layout  new_layout 
)
overrideprivatevirtual

Called at the start of the default implementation of DoReallocate.

By default, does nothing. Derived types may implement this method to add additional behavior. If they do, they must call DoBeforeReallocate on their base type just before returning.

ptr is guaranteed to be non-null, and new_layout.size() is guaranteed to be non-zero.

Reimplemented from pw::allocator::ForwardingAllocator.

◆ DoDeallocate()

template<typename MetricsType >
void pw::allocator::TrackingAllocator< MetricsType >::DoDeallocate ( void *  ptr)
overrideprivatevirtual

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::allocator::ForwardingAllocator.

◆ DoResize()

template<typename MetricsType >
bool pw::allocator::TrackingAllocator< MetricsType >::DoResize ( void *  ptr,
size_t  new_size 
)
overrideprivatevirtual

Modifies the size of an previously-allocated block of memory without copying any data.

Returns true if its size was changed without copying data to a new allocation; otherwise returns false.

In particular, it always returns true if the old_layout.size() equals new_size, and always returns false if the given pointer is null, the old_layout.size() is 0, or the new_size is 0.

Parameters
[in]ptrPointer to previously-allocated memory.
[in]new_sizeRequested new size for the memory allocation.

Reimplemented from pw::allocator::ForwardingAllocator.