16#include "pw_allocator/allocator.h"
17#include "pw_allocator/capability.h"
18#include "pw_bytes/span.h"
20namespace pw::allocator {
28 void Destroy() { DoDestroy(); }
31 virtual void DoDestroy() = 0;
41 void set_object(T*
object) { object_ = object; }
44 void DoDestroy()
override {
45 if (object_ !=
nullptr) {
46 std::destroy_at(object_);
76 static constexpr Capabilities kCapabilities = kSkipsDestroy;
87 void Init(ByteSpan region);
99 template <
typename T,
int&... ExplicitGuard,
typename... Args>
102 T* ptr = owned !=
nullptr ? New<T>(std::forward<Args>(args)...) :
nullptr;
103 if (ptr !=
nullptr) {
104 owned->set_object(ptr);
105 owned->set_next(owned_);
121 template <
typename T,
int&... ExplicitGuard,
typename... Args>
123 return WrapUnique<T>(NewOwned<T>(std::forward<Args>(args)...));
128 void* DoAllocate(
Layout layout)
override;
131 void DoDeallocate(
void*)
override;
Definition: allocator.h:32
Definition: unique_ptr.h:47
Definition: bump_allocator.h:74
T * NewOwned(Args &&... args)
Definition: bump_allocator.h:100
UniquePtr< T > MakeUniqueOwned(Args &&... args)
Definition: bump_allocator.h:122
void Init(ByteSpan region)
Sets the memory region to be used by the allocator.
constexpr BumpAllocator()
Constructs a BumpAllocator without initializing it.
Definition: bump_allocator.h:79
BumpAllocator(ByteSpan region)
Constructs a BumpAllocator and initializes it.
Definition: bump_allocator.h:82
Definition: capability.h:64
Type-erased base class to allow destroying a generic instance of Owned.
Definition: bump_allocator.h:24
Definition: bump_allocator.h:39