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_);
80 static constexpr Capabilities kCapabilities = kSkipsDestroy;
103 template <
typename T,
int&... kExplicitGuard,
typename... Args>
106 T* ptr = owned !=
nullptr ? New<T>(std::forward<Args>(args)...) :
nullptr;
107 if (ptr !=
nullptr) {
108 owned->set_object(ptr);
109 owned->set_next(owned_);
125 template <
typename T,
int&... kExplicitGuard,
typename... Args>
127 return UniquePtr<T>(NewOwned<T>(std::forward<Args>(args)...), *
this);
143 size_t allocated_ = 0;
Definition: allocator.h:36
Definition: bump_allocator.h:78
T * NewOwned(Args &&... args)
Definition: bump_allocator.h:104
size_t DoGetAllocated() const override
Definition: bump_allocator.h:138
UniquePtr< T > MakeUniqueOwned(Args &&... args)
Definition: bump_allocator.h:126
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:83
BumpAllocator(ByteSpan region)
Constructs a BumpAllocator and initializes it.
Definition: bump_allocator.h:86
void DoDeallocate(void *) override
Definition: capability.h:64
Type-erased base class to allow destroying a generic instance of Owned.
Definition: bump_allocator.h:26
Definition: bump_allocator.h:41