KTL
ktl::freelist< Min, Max, Alloc > Class Template Reference

An allocator which allocates using its underlying allocator. Only allocates if the requested size is within the Min and Max range When deallocating it chains the memory in a linked list, which can then be reused. More...

#include <freelist.h>

Public Types

typedef detail::get_size_type_t< Alloc > size_type
 

Public Member Functions

template<typename A = Alloc>
 freelist () noexcept(std::is_nothrow_default_constructible_v< A >)
 
template<typename... Args, typename = std::enable_if_t< std::is_constructible_v<Alloc, Args...>>>
 freelist (Args &&... args) noexcept(std::is_nothrow_constructible_v< Alloc, Args... >)
 Constructor for forwarding any arguments to the underlying allocator. More...
 
 freelist (const freelist &)=delete
 
 freelist (freelist &&other) noexcept(std::is_nothrow_move_constructible_v< Alloc >)
 
 ~freelist ()
 
freelistoperator= (const freelist &)=delete
 
freelistoperator= (freelist &&rhs) noexcept(std::is_nothrow_move_assignable_v< Alloc >)
 
bool operator== (const freelist &rhs) const noexcept(detail::has_nothrow_equal_v< Alloc >)
 
bool operator!= (const freelist &rhs) const noexcept(detail::has_nothrow_not_equal_v< Alloc >)
 
void * allocate (size_type n) noexcept(detail::has_nothrow_allocate_v< Alloc >)
 Attempts to allocate a chunk of memory defined by n. Will use previous allocations that were meant to be deallocated. More...
 
void deallocate (void *p, size_type n) noexcept
 Attempts to deallocate the memory at location p. More...
 
template<typename T , typename... Args>
std::enable_if< detail::has_construct_v< Alloc, T *, Args... >, void >::type construct (T *p, Args &&... args) noexcept(detail::has_nothrow_construct_v< Alloc, T *, Args... >)
 Constructs an object of T with the given ...args at the given location. More...
 
template<typename T >
std::enable_if< detail::has_destroy_v< Alloc, T * >, void >::type destroy (T *p) noexcept(detail::has_nothrow_destroy_v< Alloc, T * >)
 Destructs an object of T at the given location. More...
 
template<typename A = Alloc>
std::enable_if< detail::has_max_size_v< A >, size_type >::type max_size () const noexcept(detail::has_nothrow_max_size_v< A >)
 Returns the maximum size that an allocation can be. More...
 
template<typename A = Alloc>
std::enable_if< detail::has_owns_v< A >, bool >::type owns (void *p) const noexcept(detail::has_nothrow_owns_v< A >)
 Returns whether or not the allocator owns the given location in memory. More...
 
Alloc & get_allocator () noexcept
 Returns a reference to the underlying allocator. More...
 
const Alloc & get_allocator () const noexcept
 Returns a const reference to the underlying allocator. More...
 

Detailed Description

template<size_t Min, size_t Max, typename Alloc>
class ktl::freelist< Min, Max, Alloc >

An allocator which allocates using its underlying allocator. Only allocates if the requested size is within the Min and Max range When deallocating it chains the memory in a linked list, which can then be reused.

Note
The memory is only completely dealloacated when the allocator is destroyed. The value of Max must be at least the size of a pointer, otherwise it cannot chain deallocations.
Template Parameters
AllocThe allocator to wrap around

Member Typedef Documentation

◆ size_type

template<size_t Min, size_t Max, typename Alloc >
typedef detail::get_size_type_t<Alloc> ktl::freelist< Min, Max, Alloc >::size_type

Constructor & Destructor Documentation

◆ freelist() [1/4]

template<size_t Min, size_t Max, typename Alloc >
template<typename A = Alloc>
ktl::freelist< Min, Max, Alloc >::freelist ( )
inlinenoexcept

◆ freelist() [2/4]

template<size_t Min, size_t Max, typename Alloc >
template<typename... Args, typename = std::enable_if_t< std::is_constructible_v<Alloc, Args...>>>
ktl::freelist< Min, Max, Alloc >::freelist ( Args &&...  args)
inlineexplicitnoexcept

Constructor for forwarding any arguments to the underlying allocator.

◆ freelist() [3/4]

template<size_t Min, size_t Max, typename Alloc >
ktl::freelist< Min, Max, Alloc >::freelist ( const freelist< Min, Max, Alloc > &  )
delete

◆ freelist() [4/4]

template<size_t Min, size_t Max, typename Alloc >
ktl::freelist< Min, Max, Alloc >::freelist ( freelist< Min, Max, Alloc > &&  other)
inlinenoexcept

◆ ~freelist()

template<size_t Min, size_t Max, typename Alloc >
ktl::freelist< Min, Max, Alloc >::~freelist ( )
inline

Member Function Documentation

◆ allocate()

template<size_t Min, size_t Max, typename Alloc >
void* ktl::freelist< Min, Max, Alloc >::allocate ( size_type  n)
inlinenoexcept

Attempts to allocate a chunk of memory defined by n. Will use previous allocations that were meant to be deallocated.

Note
If n is not within Min and Max, this function will return nullptr
Parameters
nThe amount of bytes to allocate memory for
Returns
A location in memory that is at least n bytes big or nullptr if it could not be allocated

◆ construct()

template<size_t Min, size_t Max, typename Alloc >
template<typename T , typename... Args>
std::enable_if<detail::has_construct_v<Alloc, T*, Args...>, void>::type ktl::freelist< Min, Max, Alloc >::construct ( T *  p,
Args &&...  args 
)
inlinenoexcept

Constructs an object of T with the given ...args at the given location.

Note
Only defined if the underlying allocator defines it
Template Parameters
...ArgsThe types of the arguments
Parameters
pThe location of the object in memory
...argsA range of arguments to use to construct the object

◆ deallocate()

template<size_t Min, size_t Max, typename Alloc >
void ktl::freelist< Min, Max, Alloc >::deallocate ( void *  p,
size_type  n 
)
inlinenoexcept

Attempts to deallocate the memory at location p.

Note
Will not deallocate the memory, but instead tie it to a linked list for later reuse
Parameters
pThe location in memory to deallocate
nThe size that was initially allocated

◆ destroy()

template<size_t Min, size_t Max, typename Alloc >
template<typename T >
std::enable_if<detail::has_destroy_v<Alloc, T*>, void>::type ktl::freelist< Min, Max, Alloc >::destroy ( T *  p)
inlinenoexcept

Destructs an object of T at the given location.

Note
Only defined if the underlying allocator defines it
Parameters
pThe location of the object in memory

◆ get_allocator() [1/2]

template<size_t Min, size_t Max, typename Alloc >
const Alloc& ktl::freelist< Min, Max, Alloc >::get_allocator ( ) const
inlinenoexcept

Returns a const reference to the underlying allocator.

Returns
The allocator

◆ get_allocator() [2/2]

template<size_t Min, size_t Max, typename Alloc >
Alloc& ktl::freelist< Min, Max, Alloc >::get_allocator ( )
inlinenoexcept

Returns a reference to the underlying allocator.

Returns
The allocator

◆ max_size()

template<size_t Min, size_t Max, typename Alloc >
template<typename A = Alloc>
std::enable_if<detail::has_max_size_v<A>, size_type>::type ktl::freelist< Min, Max, Alloc >::max_size ( ) const
inlinenoexcept

Returns the maximum size that an allocation can be.

Note
Only defined if the underlying allocator defines it
Returns
The maximum size an allocation may be

◆ operator!=()

template<size_t Min, size_t Max, typename Alloc >
bool ktl::freelist< Min, Max, Alloc >::operator!= ( const freelist< Min, Max, Alloc > &  rhs) const
inlinenoexcept

◆ operator=() [1/2]

template<size_t Min, size_t Max, typename Alloc >
freelist& ktl::freelist< Min, Max, Alloc >::operator= ( const freelist< Min, Max, Alloc > &  )
delete

◆ operator=() [2/2]

template<size_t Min, size_t Max, typename Alloc >
freelist& ktl::freelist< Min, Max, Alloc >::operator= ( freelist< Min, Max, Alloc > &&  rhs)
inlinenoexcept

◆ operator==()

template<size_t Min, size_t Max, typename Alloc >
bool ktl::freelist< Min, Max, Alloc >::operator== ( const freelist< Min, Max, Alloc > &  rhs) const
inlinenoexcept

◆ owns()

template<size_t Min, size_t Max, typename Alloc >
template<typename A = Alloc>
std::enable_if<detail::has_owns_v<A>, bool>::type ktl::freelist< Min, Max, Alloc >::owns ( void *  p) const
inlinenoexcept

Returns whether or not the allocator owns the given location in memory.

Note
Only defined if the underlying allocator defines it
Parameters
pThe location of the object in memory
Returns
Whether the allocator owns p

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