18#include "pw_allocator/chunk_pool.h"
19#include "pw_allocator/hardening.h"
20#include "pw_bytes/span.h"
22namespace pw::allocator {
39 static constexpr size_t SizeNeeded(
size_t num_objects);
43 return std::max(
alignof(T), ChunkPool::kMinAlignment);
47 template <
size_t kNumObjects>
49 static_assert(kNumObjects != 0);
65 template <
size_t kNumObjects>
89 template <
int&... kExplicitGuard,
typename... Args>
90 T* New(Args&&... args);
98 template <
int&... kExplicitGuard,
typename... Args>
110 size_t needed = std::max(
sizeof(T), ChunkPool::kMinSize);
111 Hardening::Multiply(needed, num_objects);
116template <
int&... kExplicitGuard,
typename... Args>
118 void* ptr = Allocate();
119 return ptr !=
nullptr ?
new (ptr) T(std::forward<Args>(args)...) :
nullptr;
Definition: unique_ptr.h:44
Definition: chunk_pool.h:32
Definition: typed_pool.h:36
TypedPool(Buffer< kNumObjects > &buffer)
Definition: typed_pool.h:66
T * New(Args &&... args)
Definition: typed_pool.h:117
TypedPool(ByteSpan region)
Definition: typed_pool.h:81
static constexpr size_t SizeNeeded(size_t num_objects)
Returns the amount of memory needed to allocate num_objects.
Definition: typed_pool.h:109
UniquePtr< T > MakeUnique(Args &&... args)
Definition: typed_pool.h:99
static constexpr size_t AlignmentNeeded()
Returns the optimal alignment for the backing memory region.
Definition: typed_pool.h:42
Provides aligned storage for kNumObjects of type T.
Definition: typed_pool.h:48