libhatchet
Loading...
Searching...
No Matches
hxfree_list< T, capacity_ > Class Template Reference

#include <hxfree_list.hpp>

Classes

class  deleter_t

Public Types

using value_t = T
using ptr_t = hxptr<T, deleter_t>

Public Member Functions

 hxfree_list (void) noexcept
 hxfree_list (hxfree_list &&x_) noexcept
 ~hxfree_list (void) noexcept
template<typename... args_t_>
hxptr< T, deleter_t > allocate (args_t_ &&... args_) noexcept
hxsize_t capacity (void) const
deleter_t deleter (void) noexcept
bool empty (void) const
bool is_allocator (const T *p_) const noexcept
template<typename deleter_t_>
bool is_allocator (const hxptr< T, deleter_t_ > &ptr_) const noexcept
hxsize_t max_size (void) const
void release (T *p_) noexcept
template<typename deleter_t_>
void release (hxptr< T, deleter_t_ > &&ptr_) noexcept
void reserve (hxsize_t size_, hxsystem_allocator_t allocator_=hxsystem_allocator_current, hxalignment_t alignment_=hxalignment) noexcept
hxsize_t size (void) const
template<typename... args_t_>
hxptr< T, deleter_t > try_allocate (args_t_ &&... args_) noexcept

Detailed Description

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
class hxfree_list< T, capacity_ >

hxfree_list - A fixed-capacity pool of T managed by a singly linked free list.

Once capacity is established (statically or via reserve), allocate constructs a T and returns an hxptr owning it. release accepts either the hxptr returned by allocate or a raw pointer, destructs *p, and returns its slot to the list.

When capacity is hxallocator_dynamic_capacity, storage must be allocated by calling reserve before use.

Member Typedef Documentation

◆ ptr_t

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxfree_list< T, capacity_ >::ptr_t = hxptr<T, deleter_t>

ptr_t - Publish the hxptr type.

◆ value_t

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
using hxfree_list< T, capacity_ >::value_t = T

value_t - Publishes the value type.

Constructor & Destructor Documentation

◆ hxfree_list() [1/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxfree_list< T, capacity_ >::hxfree_list ( void )
explicitnoexcept

When capacity is hxallocator_dynamic_capacity storage must be allocated via reserve before use.

◆ hxfree_list() [2/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxfree_list< T, capacity_ >::hxfree_list ( hxfree_list< T, capacity_ > && x_)
noexcept

Move constructs from a temporary hxfree_list.

Requires hxallocator_dynamic_capacity.

◆ ~hxfree_list()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxfree_list< T, capacity_ >::~hxfree_list ( void )
noexcept

All T must have been released before destruction.

Member Function Documentation

◆ allocate()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
hxptr< T, deleter_t > hxfree_list< T, capacity_ >::allocate ( args_t_ &&... args_)
noexcept

Constructs a T in a free slot and returns an hxptr owning it.

Use release() to transfer to a different hxptr type.

  • args : Arguments forwarded to T's constructor.

◆ capacity()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxfree_list< T, capacity_ >::capacity ( void ) const

Returns the capacity of the pool or 0 if unallocated.

◆ deleter()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
deleter_t hxfree_list< T, capacity_ >::deleter ( void )
inlinenoexcept

Returns a deleter_t associated with this hxfree_list.

◆ empty()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxfree_list< T, capacity_ >::empty ( void ) const
inline

Returns true if no unallocated T remains.

◆ is_allocator() [1/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename deleter_t_>
bool hxfree_list< T, capacity_ >::is_allocator ( const hxptr< T, deleter_t_ > & ptr_) const
noexcept

Returns true if ptr points into this free list's storage.

  • ptr : The hxptr to test.

◆ is_allocator() [2/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
bool hxfree_list< T, capacity_ >::is_allocator ( const T * p_) const
noexcept

Returns true if p points into this free list's storage.

  • p : The pointer to test. May be null.

◆ max_size()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxfree_list< T, capacity_ >::max_size ( void ) const
inline

Returns the capacity of the pool.

◆ release() [1/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename deleter_t_>
void hxfree_list< T, capacity_ >::release ( hxptr< T, deleter_t_ > && ptr_)
noexcept

Destructs the object owned by ptr and returns its slot to the free list.

  • ptr : An hxptr previously returned by allocate. Must not be null.

◆ release() [2/2]

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxfree_list< T, capacity_ >::release ( T * p_)
noexcept

Destructs *p and returns its slot to the free list.

  • p : A non-null pointer previously returned by allocate.

◆ reserve()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
void hxfree_list< T, capacity_ >::reserve ( hxsize_t size_,
hxsystem_allocator_t allocator_ = hxsystem_allocator_current,
hxalignment_t alignment_ = hxalignment )
noexcept

Allocates storage for size slots and enqueues them when capacity is hxallocator_dynamic_capacity.

The current capacity becomes size slots. Reallocation is not allowed. When capacity is fixed, size must equal capacity.

  • size : The number of slots to allocate.
  • allocator : The memory manager ID to use for allocation.
  • alignment : The alignment to use for the allocation.

◆ size()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
hxsize_t hxfree_list< T, capacity_ >::size ( void ) const
inline

Returns the number of unallocated T available.

◆ try_allocate()

template<hxfree_list_concept_ T, hxsize_t capacity_ = hxallocator_dynamic_capacity>
template<typename... args_t_>
hxptr< T, deleter_t > hxfree_list< T, capacity_ >::try_allocate ( args_t_ &&... args_)
noexcept

Constructs a T in a free slot and returns an hxptr owning it.

Returns an empty hxptr when no slots remain.

  • args : Arguments forwarded to T's constructor.

The documentation for this class was generated from the following file: