18#include "pw_allocator/chunk_pool.h"
19#include "pw_allocator/hardening.h"
20#include "pw_bytes/span.h"
22namespace pw::allocator {
40 size_t needed = std::max(
sizeof(T), ChunkPool::kMinSize);
41 Hardening::Multiply(needed, num_objects);
47 return std::max(
alignof(T), ChunkPool::kMinAlignment);
51 template <
size_t kNumObjects>
53 static_assert(kNumObjects != 0);
69 template <
size_t kNumObjects>
93 template <
int&... kExplicitGuard,
typename... Args>
94 T*
New(Args&&... args) {
96 return ptr !=
nullptr ?
new (ptr) T(std::forward<Args>(args)...) :
nullptr;
105 template <
int&... kExplicitGuard,
typename... Args>
107 return UniquePtr<T>(
New(std::forward<Args>(args)...), *
this);
Definition: chunk_pool.h:32
void * Allocate()
Definition: pool.h:47
Definition: typed_pool.h:36
TypedPool(Buffer< kNumObjects > &buffer)
Definition: typed_pool.h:70
T * New(Args &&... args)
Definition: typed_pool.h:94
TypedPool(ByteSpan region)
Definition: typed_pool.h:85
static constexpr size_t SizeNeeded(size_t num_objects)
Returns the amount of memory needed to allocate num_objects.
Definition: typed_pool.h:39
UniquePtr< T > MakeUnique(Args &&... args)
Definition: typed_pool.h:106
static constexpr size_t AlignmentNeeded()
Returns the optimal alignment for the backing memory region.
Definition: typed_pool.h:46
Provides aligned storage for kNumObjects of type T.
Definition: typed_pool.h:52