ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::HugePageAllocator< T > Class Template Reference

an allocator of objects of type T, on huge pages for the large blocks More...

#include <ADS/memory/HugePageAllocator.h>

Public types

using value_type = T
 the objects

Public member functions

 HugePageAllocator (void)=default
 the allocator, which has no state
template<class U>
 HugePageAllocator (const HugePageAllocator< U > &) noexcept
 the allocator of objects of type T, from that of type U
T * allocate (std::size_t n)
 room for \( n \) objects, on huge pages if they fill one at least
void deallocate (T *p, std::size_t n) noexcept
 the room \( p \) of \( n \) objects given back: kept by the thread if it is of 8 MB or more and the cache has room, to the system otherwise
template<class U>
bool operator== (const HugePageAllocator< U > &) const noexcept
 true: the allocators are all equal

Static public attributes

static constexpr std::size_t PAGE = std::size_t( 1 ) << 21
 the size of a huge page, in bytes

Detailed description

template<class T>
class ADS::HugePageAllocator< T >

an allocator of objects of type T, on huge pages for the large blocks

Member typedef documentation

◆ value_type

template<class T>
using ADS::HugePageAllocator< T >::value_type = T

the objects

Constructor and destructor documentation

◆ HugePageAllocator() [1/2]

template<class T>
ADS::HugePageAllocator< T >::HugePageAllocator ( void )
default

the allocator, which has no state

◆ HugePageAllocator() [2/2]

template<class T>
template<class U>
ADS::HugePageAllocator< T >::HugePageAllocator ( const HugePageAllocator< U > & )
inlinenoexcept

the allocator of objects of type T, from that of type U

Member function documentation

◆ allocate()

template<class T>
T * ADS::HugePageAllocator< T >::allocate ( std::size_t n)
inlinenodiscard

room for \( n \) objects, on huge pages if they fill one at least

In pseudocode (Navarro et al., beyond the book), \( P = 2^{21} \) the bytes of a huge page:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{allocate}( n ) \cr 2 & \quad b \gets n \cdot \mathrm{sizeof}( T ) \cr 3 & \quad \textbf{if}\ b < P\ \textbf{then return}\ \text{the memory} \text{ of std::allocator} \cr 4 & \quad r \gets P \lceil b / P \rceil \cr 5 & \quad \textbf{if}\ \text{this thread keeps a block of } r \text{ } \text{bytes}\ \textbf{then return}\ \text{it, no longer kept} \cr 6 & \quad \textbf{return}\ \text{a block of } r \text{ bytes aligned} \text{ to } P \end{array}} \]

◆ deallocate()

template<class T>
void ADS::HugePageAllocator< T >::deallocate ( T * p,
std::size_t n )
inlinenoexcept

the room \( p \) of \( n \) objects given back: kept by the thread if it is of 8 MB or more and the cache has room, to the system otherwise

Precondition
\( p \) was given by allocate( n )

◆ operator==()

template<class T>
template<class U>
bool ADS::HugePageAllocator< T >::operator== ( const HugePageAllocator< U > & ) const
inlinenoexcept

true: the allocators are all equal

Member data documentation

◆ PAGE

template<class T>
std::size_t ADS::HugePageAllocator< T >::PAGE = std::size_t( 1 ) << 21
staticconstexpr

the size of a huge page, in bytes


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