18#include "pw_allocator/chunk_pool.h"
19#include "pw_allocator/hardening.h"
20#include "pw_bytes/span.h"
22namespace pw::allocator {
38 size_t needed = std::max(
sizeof(T), ChunkPool::kMinSize);
39 Hardening::Multiply(needed, num_objects);
45 return std::max(
alignof(T), ChunkPool::kMinAlignment);
49 template <
size_t kNumObjects>
51 static_assert(kNumObjects != 0);
67 template <
size_t kNumObjects>
91 template <
int&... kExplicitGuard,
typename... Args>
92 T*
New(Args&&... args) {
94 return ptr !=
nullptr ?
new (ptr) T(std::forward<Args>(args)...) :
nullptr;
103 template <
int&... kExplicitGuard,
typename... Args>
105 return Deallocator::WrapUnique<T>(
New(std::forward<Args>(args)...));
Definition: chunk_pool.h:30
void * Allocate()
Definition: pool.h:44
Definition: typed_pool.h:34
TypedPool(Buffer< kNumObjects > &buffer)
Definition: typed_pool.h:68
T * New(Args &&... args)
Definition: typed_pool.h:92
TypedPool(ByteSpan region)
Definition: typed_pool.h:83
static constexpr size_t SizeNeeded(size_t num_objects)
Returns the amount of memory needed to allocate num_objects.
Definition: typed_pool.h:37
UniquePtr< T > MakeUnique(Args &&... args)
Definition: typed_pool.h:104
static constexpr size_t AlignmentNeeded()
Returns the optimal alignment for the backing memory region.
Definition: typed_pool.h:44
Provides aligned storage for kNumObjects of type T.
Definition: typed_pool.h:50