18#include "pw_allocator/capability.h"
19#include "pw_allocator/hardening.h"
20#include "pw_allocator/layout.h"
21#include "pw_result/result.h"
22#include "pw_status/status.h"
23#include "pw_status/status_with_size.h"
38 constexpr const Capabilities& capabilities()
const {
return capabilities_; }
42 return capabilities_.has(capability);
75 int&... kExplicitGuard,
76 std::enable_if_t<!std::is_array_v<T>,
int> = 0>
80 int&... kExplicitGuard,
81 typename ElementType = std::remove_extent_t<T>,
82 std::enable_if_t<is_bounded_array_v<T>,
int> = 0>
83 void Delete(ElementType* ptr);
86 int&... kExplicitGuard,
87 typename ElementType = std::remove_extent_t<T>,
88 std::enable_if_t<is_unbounded_array_v<T>,
int> = 0>
89 void Delete(ElementType* ptr,
size_t count);
104 template <
typename ElementType>
131 template <
typename T>
132 static constexpr bool is_bounded_array_v = ::pw::is_bounded_array_v<T>;
134 template <
typename T>
135 static constexpr bool is_unbounded_array_v = ::pw::is_unbounded_array_v<T>;
141 : capabilities_(capabilities) {}
244 return deallocator.
DoGetInfo(info_type, ptr);
309 const Capabilities capabilities_;
317 if (ptr !=
nullptr) {
323 int&... kExplicitGuard,
324 std::enable_if_t<!std::is_array_v<T>,
int>>
326 if constexpr (allocator::Hardening::kIncludesDebugChecks) {
328 if constexpr (std::has_virtual_destructor_v<T>) {
329 PW_ASSERT(result->size() >=
sizeof(T) &&
330 result->alignment() >=
alignof(T));
332 PW_ASSERT(*result == Layout::Of<T>());
336 DeleteArray<T>(ptr, 1);
340 int&... kExplicitGuard,
341 typename ElementType,
342 std::enable_if_t<is_bounded_array_v<T>,
int>>
344 size_t count = std::extent_v<T>;
346 DeleteArray<ElementType>(&ptr[0], count);
351 int&... kExplicitGuard,
352 typename ElementType,
353 std::enable_if_t<is_unbounded_array_v<T>,
int>>
355 DeleteArray<ElementType>(ptr, count);
358template <
typename ElementType>
360 if (!capabilities_.has(Capability::kSkipsDestroy)) {
361 std::destroy_n(ptr, count);
Abstract interface for releasing memory.
Definition: deallocator.h:30
bool Recognizes(const void *ptr) const
Definition: deallocator.h:288
static Result< Layout > GetRequestedLayout(const Deallocator &deallocator, const void *ptr)
Definition: deallocator.h:255
virtual void DoDeallocate(void *ptr)=0
Result< Layout > GetUsableLayout(const void *ptr) const
Definition: deallocator.h:262
static Result< Layout > GetInfo(const Deallocator &deallocator, InfoType info_type, const void *ptr)
Definition: deallocator.h:241
virtual Result< Layout > DoGetInfo(InfoType, const void *) const
Definition: deallocator.h:304
void Delete(T *ptr)
Definition: deallocator.h:325
StatusWithSize GetCapacity() const
Definition: deallocator.h:366
Result< Layout > GetRequestedLayout(const void *ptr) const
Definition: deallocator.h:249
InfoType
Definition: deallocator.h:173
void DeleteArray(ElementType *ptr, size_t count)
Definition: deallocator.h:359
void Deallocate(void *ptr)
Definition: deallocator.h:316
constexpr bool HasCapability(Capability capability) const
Returns whether a given capability is enabled for this object.
Definition: deallocator.h:41
Result< Layout > GetAllocatedLayout(const void *ptr) const
Definition: deallocator.h:275
static Result< Layout > GetUsableLayout(const Deallocator &deallocator, const void *ptr)
Definition: deallocator.h:268
Result< Layout > GetInfo(InfoType info_type, const void *ptr) const
Definition: deallocator.h:232
static Result< Layout > GetAllocatedLayout(const Deallocator &deallocator, const void *ptr)
Definition: deallocator.h:281
static bool Recognizes(const Deallocator &deallocator, const void *ptr)
Definition: deallocator.h:294
bool IsEqual(const Deallocator &other) const
Definition: deallocator.h:126
constexpr Deallocator()=default
TODO(b/326509341): Remove when downstream consumers migrate.
static constexpr Status Unimplemented()
Definition: status.h:280
Definition: status_with_size.h:51
Definition: capability.h:65
static constexpr Layout Unwrap(const Result< Layout > &result)
Definition: layout.h:93
Capability
Definition: capability.h:28
The Pigweed namespace.
Definition: alignment.h:27