18#include "pw_allocator/as_pmr_allocator.h"
19#include "pw_allocator/capability.h"
20#include "pw_allocator/deallocator.h"
21#include "pw_allocator/layout.h"
22#include "pw_allocator/unique_ptr.h"
23#include "pw_result/result.h"
41 return layout.size() != 0 ? DoAllocate(layout) :
nullptr;
51 template <
typename T,
int&... ExplicitGuard,
typename... Args>
52 T*
New(Args&&... args) {
53 void* ptr =
Allocate(Layout::Of<T>());
54 return ptr !=
nullptr ?
new (ptr) T(std::forward<Args>(args)...) :
nullptr;
64 template <
typename T,
int&... ExplicitGuard,
typename... Args>
66 return Deallocator::WrapUnique<T>(New<T>(std::forward<Args>(args)...));
81 bool Resize(
void* ptr,
size_t new_size) {
82 return ptr !=
nullptr && new_size != 0 && DoResize(ptr, new_size);
89 return ptr !=
nullptr && new_size != 0 && DoResize(ptr, layout, new_size);
116 if (new_layout.size() == 0) {
119 if (ptr ==
nullptr) {
122 return DoReallocate(ptr, new_layout);
132 if (ptr ==
nullptr) {
135 return DoReallocate(ptr, old_layout, new_size);
162 virtual void* DoAllocate(Layout layout) = 0;
171 virtual bool DoResize(
void* ,
size_t ) {
return false; }
176 virtual bool DoResize(
void*, Layout,
size_t) {
return false; }
187 virtual void* DoReallocate(
void* ptr, Layout new_layout);
192 virtual void* DoReallocate(
void* ptr, Layout old_layout,
size_t new_size);
Definition: allocator.h:32
T * New(Args &&... args)
Definition: allocator.h:52
UniquePtr< T > MakeUnique(Args &&... args)
Definition: allocator.h:65
allocator::AsPmrAllocator as_pmr()
Definition: allocator.h:146
constexpr Allocator()=default
TODO(b/326509341): Remove when downstream consumers migrate.
bool Resize(void *ptr, size_t new_size)
Definition: allocator.h:81
void * Reallocate(void *ptr, Layout new_layout)
Definition: allocator.h:115
void * Reallocate(void *ptr, Layout old_layout, size_t new_size)
Definition: allocator.h:128
bool Resize(void *ptr, Layout layout, size_t new_size)
Definition: allocator.h:88
void * Allocate(Layout layout)
Definition: allocator.h:40
Abstract interface for releasing memory.
Definition: deallocator.h:26
Definition: unique_ptr.h:47
Definition: as_pmr_allocator.h:79
Definition: capability.h:64
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27