18#include "pw_allocator/allocator.h"
19#include "pw_allocator/capability.h"
20#include "pw_bytes/span.h"
22namespace pw::allocator {
30 void Destroy() { DoDestroy(); }
33 virtual void DoDestroy() = 0;
43 void set_object(T*
object) { object_ = object; }
46 void DoDestroy()
override {
47 if (object_ !=
nullptr) {
48 std::destroy_at(object_);
78 static constexpr Capabilities kCapabilities = kSkipsDestroy;
89 void Init(ByteSpan region);
101 template <
typename T,
int&... kExplicitGuard,
typename... Args>
104 T* ptr = owned !=
nullptr ? New<T>(std::forward<Args>(args)...) :
nullptr;
105 if (ptr !=
nullptr) {
106 owned->set_object(ptr);
107 owned->set_next(owned_);
123 template <
typename T,
int&... kExplicitGuard,
typename... Args>
125 return WrapUnique<T>(NewOwned<T>(std::forward<Args>(args)...));
141 size_t allocated_ = 0;
Definition: allocator.h:34
Definition: bump_allocator.h:76
T * NewOwned(Args &&... args)
Definition: bump_allocator.h:102
size_t DoGetAllocated() const override
Definition: bump_allocator.h:136
UniquePtr< T > MakeUniqueOwned(Args &&... args)
Definition: bump_allocator.h:124
void Init(ByteSpan region)
Sets the memory region to be used by the allocator.
void * DoAllocate(Layout layout) override
constexpr BumpAllocator()
Constructs a BumpAllocator without initializing it.
Definition: bump_allocator.h:81
BumpAllocator(ByteSpan region)
Constructs a BumpAllocator and initializes it.
Definition: bump_allocator.h:84
void DoDeallocate(void *) override
Definition: capability.h:62
Type-erased base class to allow destroying a generic instance of Owned.
Definition: bump_allocator.h:26
Definition: bump_allocator.h:41