Skip to main content
Pigweed's logo Pigweed
code_xml
  1. Home
  2. Reference
  3. C/C++
  4. pw::allocator::internal::BaseFramingAllocator< ErrorHandler > Class Template Reference
Loading...
Searching...
No Matches
pw::allocator::internal::BaseFramingAllocator< ErrorHandler > Class Template Reference

Overview

template<typename ErrorHandler>
class pw::allocator::internal::BaseFramingAllocator< ErrorHandler >

Provides generic framing logic for type-erased prefixes and suffixes.

Template Parameters
ErrorHandlerInvoked when a frame error is encountered.
Inheritance diagram for pw::allocator::internal::BaseFramingAllocator< ErrorHandler >:
pw::allocator::ForwardingAllocator pw::Allocator pw::Deallocator pw::allocator::FramingAllocator< SourceLocation > pw::allocator::FramingAllocator< pw::tokenizer::Token > pw::allocator::FramingAllocator< void, size_t, ErrorHandler > pw::allocator::FramingAllocator< void, size_t, internal::DefaultGuardErrorHandler > pw::allocator::FramingAllocator< Prefix, Suffix, ErrorHandler > pw::allocator::OriginAllocator pw::allocator::TaggingAllocator pw::allocator::internal::BasicGuardedAllocator< ErrorHandler > pw::allocator::internal::BasicGuardedAllocator< internal::DefaultGuardErrorHandler >

Protected Member Functions

constexpr BaseFramingAllocator (Allocator &allocator)
 
ByteSpan AllocateFrame (Layout prefix, Layout data, Layout suffix)
 
bool ResizeFrame (void *data, size_t new_size, Layout suffix, void *tmp_suffix)
 
Result< Layout > GetFrameInfo (InfoType info_type, const void *data, Layout suffix) const
 
Result< size_t > GetFrameSize (const void *frame) const
 
- Protected Member Functions inherited from pw::allocator::ForwardingAllocator
constexpr ForwardingAllocator (const Capabilities &capabilities) noexcept
 
constexpr ForwardingAllocator (pw::Allocator &allocator) noexcept
 
constexpr void Init (pw::Allocator &allocator)
 
constexpr pw::Allocator & allocator ()
 
constexpr const pw::Allocator & allocator () const
 
void * DoAllocate (Layout layout) override
 
void DoDeallocate (void *ptr) override
 
bool DoResize (void *ptr, size_t new_size) override
 
bool DoBeforeReallocate (void *ptr, Layout new_layout) override
 
void DoAfterReallocateCopy (void *ptr, Layout new_layout, void *new_ptr) override
 
void DoAfterReallocateDone (Layout new_layout, void *new_ptr) override
 
size_t DoGetAllocated () const override
 
std::optional< Fragmentation > DoMeasureFragmentation () const override
 Returns fragmentation information for the allocator's memory region.
 
Result< Layout > DoGetInfo (InfoType info_type, const void *ptr) const override
 
- Protected Member Functions inherited from pw::Allocator
constexpr Allocator () noexcept=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Allocator (const Capabilities &capabilities) noexcept
 
virtual void * DoAllocate (Layout layout)=0
 
virtual bool DoResize (void *ptr, size_t new_size)
 
virtual void * DoReallocate (void *ptr, Layout new_layout)
 
virtual bool DoBeforeReallocate (void *ptr, Layout new_layout)
 
virtual void DoAfterReallocateCopy (void *ptr, Layout new_layout, void *new_ptr)
 
virtual void DoAfterReallocateDone (Layout new_layout, void *new_ptr)
 
virtual size_t DoGetAllocated () const
 
virtual std::optional< Fragmentation > DoMeasureFragmentation () 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< Layout > GetInfo (InfoType info_type, const void *ptr) const
 
Result< Layout > GetRequestedLayout (const void *ptr) const
 
Result< Layout > GetUsableLayout (const void *ptr) const
 
Result< Layout > GetAllocatedLayout (const void *ptr) const
 
bool Recognizes (const void *ptr) const
 
virtual void DoDeallocate (void *ptr)=0
 
virtual Result< Layout > DoGetInfo (InfoType, const void *) const
 

Static Protected Member Functions

static constexpr size_t Distance (const void *start, const void *end)
 Returns the distance between two pointers in bytes.
 
static void UpdateOffsets (void *frame, void *data, void *suffix)
 
static void * GetFrame (void *data, bool has_suffix, bool checked=true)
 
static const void * GetFrame (const void *data, bool has_suffix, bool checked=true)
 
static void * GetData (void *frame, Result< size_t > frame_size, Layout prefix)
 
static const void * GetData (const void *frame, Result< size_t > frame_size, Layout prefix)
 
static void * GetSuffix (void *data, size_t data_size, Layout suffix)
 
static const void * GetSuffix (const void *data, size_t data_size, Layout suffix)
 
- Static Protected Member Functions inherited from pw::Allocator
static bool BeforeReallocate (Allocator &allocator, void *ptr, Layout new_layout)
 
static void AfterReallocateCopy (Allocator &allocator, void *ptr, Layout new_layout, void *new_ptr)
 
static void AfterReallocateDone (Allocator &allocator, Layout new_layout, void *new_ptr)
 
- Static Protected Member Functions inherited from pw::Deallocator
static Result< Layout > GetInfo (const Deallocator &deallocator, InfoType info_type, const void *ptr)
 
static Result< Layout > GetRequestedLayout (const Deallocator &deallocator, const void *ptr)
 
static Result< Layout > GetUsableLayout (const Deallocator &deallocator, const void *ptr)
 
static Result< Layout > GetAllocatedLayout (const Deallocator &deallocator, const void *ptr)
 
static bool Recognizes (const Deallocator &deallocator, const void *ptr)
 

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
 
- 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< Fragmentation > MeasureFragmentation () const
 Returns fragmentation information for the allocator's memory region.
 
- Public Member Functions inherited from pw::Deallocator
constexpr const Capabilities & capabilities () 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 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

◆ AllocateFrame()

template<typename ErrorHandler >
ByteSpan pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::AllocateFrame ( Layout  prefix,
Layout  data,
Layout  suffix 
)
protected

Allocates a frame that can hold the requested data framed by a prefix and/or suffix, and returns it as a span of bytes.

Parameters
prefixLayout of the type-erased prefix.
dataRequested layout.
suffixLayout of the type-erased suffix.

◆ GetData()

template<typename ErrorHandler >
void * pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::GetData ( void *  frame,
Result< size_t >  frame_size,
Layout  prefix 
)
staticprotected

Returns a data pointer from a frame pointer.

Parameters
framePointer to an underlying allocation.
frame_sizeSize of the frame.
prefixLayout of the type-erased prefix, or a default layout.

◆ GetFrame()

template<typename ErrorHandler >
void * pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::GetFrame ( void *  data,
bool  has_suffix,
bool  checked = true 
)
staticprotected

Returns a frame pointer from a data pointer.

Unlike many of the other pointer conversion methods, this method includes a checked parameter that can be set to false to avoid calling the error handler. This is useful when the returned frame pointer is intended to be passed to a method that accepts any pointer, e.g. a Deallocator method that returns pw::Status::NotFound() for invalid pointers.

Parameters
dataPointer to usable memory.
has_suffixUsed to locate the data-relative prefix offset.
checkedIf false, the ErrorHandler is never called.

◆ GetFrameInfo()

template<typename ErrorHandler >
Result< Layout > pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::GetFrameInfo ( InfoType  info_type,
const void *  data,
Layout  suffix 
) const
protected

Returns info like Deallocator::GetInfo.

Parameters
info_typeSee Deallocator::InfoType.
dataPointer to usable memory.
suffixLayout of the type-erased suffix, or a default layout.

◆ GetFrameSize()

template<typename ErrorHandler >
Result< size_t > pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::GetFrameSize ( const void *  frame) const
protected

Returns the usable size of an underlying allocation.

Returns
A Result containing size of the frame on success or one of the following error codes on failure:
  • OK: Returns the size of the frame in bytes.
  • NOT_FOUND: Frame is not recognized by the underlying allocator.
  • UNIMPLEMENTED: The underlying allocator cannot get usable sizes.

◆ GetSuffix()

template<typename ErrorHandler >
void * pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::GetSuffix ( void *  data,
size_t  data_size,
Layout  suffix 
)
staticprotected

Returns a frame pointer from a data pointer.

Parameters
dataPointer to usable memory.
data_sizeSize of the memory from data to the end of the frame, including the suffix.
suffixLayout of the type-erased suffix, or a default layout.

◆ ResizeFrame()

template<typename ErrorHandler >
bool pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::ResizeFrame ( void *  data,
size_t  new_size,
Layout  suffix,
void *  tmp_suffix 
)
protected

Resizes a frame that holds the provided data to be at least the new size while keeping the (type-erased) prefix and/or suffix.

Returns
Whether the frame was successfully resized.
Parameters
dataPointer to usable memory.
new_sizeRequested new size of the usable memory.
suffixLayout of the type-erased suffix, or a default layout.
tmp_suffixPointer to a temporary suffix, or null.

◆ UpdateOffsets()

template<typename ErrorHandler >
void pw::allocator::internal::BaseFramingAllocator< ErrorHandler >::UpdateOffsets ( void *  frame,
void *  data,
void *  suffix 
)
staticprotected

Updates the frame-relative and data-relative prefix offsets, and the suffix offset as needed for the given pointers to locations in the frame.

Parameters
framePointer to the underlying allocation.
dataPointer to the usable memory.
suffixPointer to the type-erased suffix, or null.

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