18#include "pw_allocator/allocator.h"
19#include "pw_allocator/chunk_pool.h"
20#include "pw_bytes/span.h"
21#include "pw_result/result.h"
23namespace pw::allocator {
39 size_t needed = std::max(
sizeof(T), ChunkPool::kMinSize);
46 return std::max(
alignof(T), ChunkPool::kMinAlignment);
50 template <
size_t kNumObjects>
52 static_assert(kNumObjects != 0);
68 template <
size_t kNumObjects>
92 template <
int&... ExplicitGuard,
typename... Args>
93 T*
New(Args&&... args) {
95 return ptr !=
nullptr ?
new (ptr) T(std::forward<Args>(args)...) :
nullptr;
104 template <
int&... ExplicitGuard,
typename... Args>
106 return Deallocator::WrapUnique<T>(
New(std::forward<Args>(args)...));
Definition: unique_ptr.h:47
Definition: chunk_pool.h:30
void * Allocate()
Definition: pool.h:44
Definition: typed_pool.h:35
TypedPool(Buffer< kNumObjects > &buffer)
Definition: typed_pool.h:69
T * New(Args &&... args)
Definition: typed_pool.h:93
TypedPool(ByteSpan region)
Definition: typed_pool.h:84
static constexpr size_t SizeNeeded(size_t num_objects)
Returns the amount of memory needed to allocate num_objects.
Definition: typed_pool.h:38
UniquePtr< T > MakeUnique(Args &&... args)
Definition: typed_pool.h:105
static constexpr size_t AlignmentNeeded()
Returns the optimal alignment for the backing memory region.
Definition: typed_pool.h:45
#define PW_MUL_OVERFLOW(a, b, out)
Definition: compiler.h:261
Provides aligned storage for kNumObjects of type T.
Definition: typed_pool.h:51