18#include "pw_allocator/abstract_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;
75 static constexpr Capabilities kCapabilities = kSkipsDestroy;
98 template <
typename T,
int&... kExplicitGuard,
typename... Args>
111 template <
typename T,
int&... kExplicitGuard,
typename... Args>
128 size_t allocated_ = 0;
140void Owned<T>::DoDestroy() {
141 if (object_ !=
nullptr) {
142 std::destroy_at(object_);
149template <
typename T,
int&... kExplicitGuard,
typename... Args>
152 T* ptr = owned !=
nullptr ? New<T>(std::forward<Args>(args)...) :
nullptr;
153 if (ptr !=
nullptr) {
154 owned->set_object(ptr);
155 owned->set_next(owned_);
161template <
typename T,
int&... kExplicitGuard,
typename... Args>
163 return UniquePtr<T>(NewOwned<T>(std::forward<Args>(args)...), *
this);
Definition: unique_ptr.h:44
Definition: abstract_allocator.h:30
Definition: bump_allocator.h:73
T * NewOwned(Args &&... args)
Definition: bump_allocator.h:150
size_t DoGetAllocated() const override
Definition: bump_allocator.h:122
UniquePtr< T > MakeUniqueOwned(Args &&... args)
Definition: bump_allocator.h:162
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:78
BumpAllocator(ByteSpan region)
Constructs a BumpAllocator and initializes it.
Definition: bump_allocator.h:81
void DoDeallocate(void *) override
Definition: capability.h:65
Type-erased base class to allow destroying a generic instance of Owned.
Definition: bump_allocator.h:26
Definition: bump_allocator.h:41