Pigweed
 
Loading...
Searching...
No Matches
pw::Deallocator Class Reference

Abstract interface for releasing memory. More...

#include <deallocator.h>

Inheritance diagram for pw::Deallocator:
pw::Allocator pw::allocator::Pool pw::allocator::SynchronizedAllocator< pw::sync::Mutex > pw::allocator::TrackingAllocator< internal::AllMetrics > pw::allocator::test::AllocatorForTest< 1024 > pw::allocator::BuddyAllocator< kMinOuterSize_, kNumBuckets > pw::allocator::BumpAllocator pw::allocator::FallbackAllocator pw::allocator::LibCAllocator pw::allocator::NullAllocator pw::allocator::SynchronizedAllocator< LockType > pw::allocator::TrackingAllocator< MetricsType > pw::allocator::internal::GenericBlockAllocator pw::allocator::test::AllocatorForTest< kBufferSize, BlockType_, MetricsType > pw::allocator::AllocatorAsPool pw::allocator::ChunkPool

Public Types

using Capabilities = allocator::Capabilities
 
using Capability = allocator::Capability
 
using Layout = allocator::Layout
 

Public Member Functions

constexpr const Capabilitiescapabilities () const
 
bool HasCapability (Capability capability) const
 Returns whether a given capabilityis enabled for this object.
 
void Deallocate (void *ptr)
 
void Deallocate (void *ptr, Layout layout)
 
template<typename T >
void Delete (T *ptr)
 
StatusWithSize GetCapacity () const
 
bool IsEqual (const Deallocator &other) const
 
template<typename T , int &... kExplicitGuard, std::enable_if_t< is_bounded_array_v< T >, int > = 0, typename... Args>
void WrapUnique (Args &&...)=delete
 

Protected Member Functions

constexpr Deallocator ()=default
 TODO(b/326509341): Remove when downstream consumers migrate.
 
constexpr Deallocator (const Capabilities &capabilities)
 
template<typename T , std::enable_if_t<!std::is_array_v< T >, int > = 0>
UniquePtr< T > WrapUnique (T *ptr)
 
template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
UniquePtr< T > WrapUnique (ElementType *ptr, size_t size)
 
template<typename T >
UniquePtr< T[]> WrapUniqueArray (T *ptr, size_t size)
 

Static Protected Attributes

template<typename T >
static constexpr bool is_bounded_array_v
 
template<typename T >
static constexpr bool is_unbounded_array_v
 

Detailed Description

Abstract interface for releasing memory.

Member Function Documentation

◆ Deallocate() [1/2]

void pw::Deallocator::Deallocate ( void *  ptr)
inline

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.

◆ Deallocate() [2/2]

void pw::Deallocator::Deallocate ( void *  ptr,
Layout  layout 
)
inline

Deprecated version of Deallocate that takes a Layout. Do not use this method. It will be removed. TODO(b/326509341): Remove when downstream consumers migrate.

◆ Delete()

template<typename T >
void pw::Deallocator::Delete ( T *  ptr)
inline

Destroys the object at ptr and deallocates the associated memory.

The given pointer must have been previously obtained from a call to New using the same object; otherwise the behavior is undefined.

Parameters
[in]ptrPointer to previously-allocated object.

◆ GetCapacity()

StatusWithSize pw::Deallocator::GetCapacity ( ) const
inline

Returns the total amount of memory provided by this object.

This is an optional method. Some memory providers may not have an easily defined capacity, e.g. the system allocator. If implemented, the returned capacity may be less than the memory originally given to an allocator, e.g. if the allocator must align the region of memory, its capacity may be reduced.

◆ IsEqual()

bool pw::Deallocator::IsEqual ( const Deallocator other) const
inline

Returns whether the given object is the same as this one.

This method is used instead of operator== in keeping with std::pmr::memory_resource::is_equal. There currently is no corresponding virtual DoIsEqual, as objects that would require dynamic_cast to properly determine equality are not supported. This method will allow the interface to remain unchanged should a future need for such objects arise.

Parameters
[in]otherObject to compare with this object.

◆ WrapUnique() [1/2]

template<typename T , int &... kExplicitGuard, typename ElementType = std::remove_extent_t<T>, std::enable_if_t< is_unbounded_array_v< T >, int > = 0>
UniquePtr< T > pw::Deallocator::WrapUnique ( ElementType *  ptr,
size_t  size 
)
inlineprotected

Wraps an array of type T in a UniquePtr

Parameters
[in]ptrPointer to memory provided by this object.
[in]sizeThe size of the array.

◆ WrapUnique() [2/2]

template<typename T , std::enable_if_t<!std::is_array_v< T >, int > = 0>
UniquePtr< T > pw::Deallocator::WrapUnique ( T *  ptr)
inlineprotected

Wraps an object of type T in a UniquePtr

Parameters
[in]ptrPointer to memory provided by this object.

◆ WrapUniqueArray()

template<typename T >
UniquePtr< T[]> pw::Deallocator::WrapUniqueArray ( T *  ptr,
size_t  size 
)
inlineprotected

Deprecated version of WrapUnique with a different name and templated on the object type instead of the array type. Do not use this method. It will be removed. TODO(b/326509341): Remove when downstream consumers migrate.

Member Data Documentation

◆ is_bounded_array_v

template<typename T >
constexpr bool pw::Deallocator::is_bounded_array_v
staticconstexprprotected
Initial value:
=
allocator::internal::is_bounded_array_v<T>

◆ is_unbounded_array_v

template<typename T >
constexpr bool pw::Deallocator::is_unbounded_array_v
staticconstexprprotected
Initial value:
=
allocator::internal::is_unbounded_array_v<T>

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