Container System 0.1.0
High-performance C++20 type-safe container framework with SIMD-accelerated serialization
Loading...
Searching...
No Matches
kcenon::container::internal Namespace Reference

Classes

class  fixed_block_pool
 
class  pool_allocator
 Thread-local pool manager for value_container allocations. More...
 
struct  pool_allocator_stats
 Extended pool statistics with hit/miss tracking. More...
 
struct  pool_size_class
 Size class thresholds for pool allocation. More...
 

Functions

template<typename T , typename... Args>
T * pool_allocate (Args &&... args) noexcept
 Allocate and construct an object using pool allocation.
 
template<typename T >
void pool_deallocate (T *ptr) noexcept
 Destroy and deallocate an object allocated with pool_allocate.
 
template<typename T >
constexpr bool is_pool_allocatable () noexcept
 Check if a type is suitable for pool allocation.
 
constexpr int get_size_class (std::size_t size) noexcept
 Get the size class for a given size.
 

Function Documentation

◆ get_size_class()

int kcenon::container::internal::get_size_class ( std::size_t size)
inlineconstexprnoexcept

Get the size class for a given size.

Parameters
sizeSize in bytes
Returns
0 for small, 1 for medium, 2 for large

Definition at line 232 of file pool_allocator.h.

232 {
233 if (size <= pool_size_class::small_threshold) {
234 return 0;
235 } else if (size <= pool_size_class::medium_threshold) {
236 return 1;
237 }
238 return 2;
239}

References kcenon::container::internal::pool_size_class::medium_threshold, and kcenon::container::internal::pool_size_class::small_threshold.

◆ is_pool_allocatable()

template<typename T >
bool kcenon::container::internal::is_pool_allocatable ( )
constexprnoexcept

Check if a type is suitable for pool allocation.

Template Parameters
TType to check
Returns
true if type fits in pool (size <= medium_threshold)

Definition at line 223 of file pool_allocator.h.

223 {
224 return sizeof(T) <= pool_size_class::medium_threshold;
225}

References kcenon::container::internal::pool_size_class::medium_threshold.

◆ pool_allocate()

template<typename T , typename... Args>
T * kcenon::container::internal::pool_allocate ( Args &&... args)
noexcept

Allocate and construct an object using pool allocation.

Template Parameters
TType to construct
ArgsConstructor argument types
Parameters
argsConstructor arguments
Returns
Pointer to constructed object, or nullptr on failure

Definition at line 185 of file pool_allocator.h.

185 {
186 static_assert(std::is_nothrow_destructible_v<T>,
187 "pool_allocate requires nothrow destructible types");
188
189 void* ptr = pool_allocator::instance().allocate(sizeof(T));
190 if (!ptr) {
191 return nullptr;
192 }
193
194 try {
195 return new (ptr) T(std::forward<Args>(args)...);
196 } catch (...) {
197 pool_allocator::instance().deallocate(ptr, sizeof(T));
198 return nullptr;
199 }
200}

References kcenon::container::internal::pool_allocator::allocate(), kcenon::container::internal::pool_allocator::deallocate(), and kcenon::container::internal::pool_allocator::instance().

Here is the call graph for this function:

◆ pool_deallocate()

template<typename T >
void kcenon::container::internal::pool_deallocate ( T * ptr)
noexcept

Destroy and deallocate an object allocated with pool_allocate.

Template Parameters
TType of object
Parameters
ptrPointer to object

Definition at line 208 of file pool_allocator.h.

208 {
209 if (!ptr) {
210 return;
211 }
212
213 ptr->~T();
214 pool_allocator::instance().deallocate(ptr, sizeof(T));
215}

References kcenon::container::internal::pool_allocator::deallocate(), and kcenon::container::internal::pool_allocator::instance().

Here is the call graph for this function: