timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::ert::aligned_allocator< Tp, AlignV > Class Template Reference

#include "timemory/ert/aligned_allocator.hpp"

+ Collaboration diagram for tim::ert::aligned_allocator< Tp, AlignV >:

Classes

struct  rebind
 

Public Types

using value_type = Tp
 
using pointer = Tp *
 
using reference = Tp &
 
using const_pointer = const Tp *
 
using const_reference = const Tp &
 
using size_type = std::size_t
 
using difference_type = ptrdiff_t
 

Public Member Functions

 aligned_allocator ()=default
 
 aligned_allocator (const aligned_allocator &)=default
 
 aligned_allocator (aligned_allocator &&) noexcept
 
template<typename U >
 aligned_allocator (const aligned_allocator< U, AlignV > &)
 
 ~aligned_allocator ()=default
 
aligned_allocatoroperator= (const aligned_allocator &)=delete
 
aligned_allocatoroperator== (aligned_allocator &&)=delete
 
bool operator!= (const aligned_allocator &other) const
 
bool operator== (const aligned_allocator &) const
 
Tp * address (Tp &r) const
 
const Tp * address (const Tp &s) const
 
std::size_t max_size () const
 
void construct (Tp *const p, const Tp &t) const
 
template<typename... ArgsT>
void construct (Tp *const p, ArgsT &&... args) const
 
void destroy (Tp *const p) const
 
Tp * allocate (const std::size_t n) const
 
void deallocate (Tp *const ptr, const std::size_t) const
 
template<typename U >
Tp * allocate (const std::size_t n, const U *) const
 
std::size_t get_alignment ()
 

Detailed Description

template<typename Tp, std::size_t AlignV = 8 * sizeof(Tp)>
class tim::ert::aligned_allocator< Tp, AlignV >

Definition at line 49 of file aligned_allocator.hpp.


Class Documentation

◆ tim::ert::aligned_allocator::rebind

struct tim::ert::aligned_allocator::rebind
template<typename Tp, std::size_t AlignV = 8 * sizeof(Tp)>
template<typename U>
struct tim::ert::aligned_allocator< Tp, AlignV >::rebind< U >

Definition at line 90 of file aligned_allocator.hpp.

+ Collaboration diagram for tim::ert::aligned_allocator< Tp, AlignV >::rebind< U >:
Class Members
typedef aligned_allocator< U, AlignV > other

Member Typedef Documentation

◆ const_pointer

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::const_pointer = const Tp*

Definition at line 56 of file aligned_allocator.hpp.

◆ const_reference

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::const_reference = const Tp&

Definition at line 57 of file aligned_allocator.hpp.

◆ difference_type

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::difference_type = ptrdiff_t

Definition at line 59 of file aligned_allocator.hpp.

◆ pointer

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::pointer = Tp*

Definition at line 54 of file aligned_allocator.hpp.

◆ reference

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::reference = Tp&

Definition at line 55 of file aligned_allocator.hpp.

◆ size_type

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::size_type = std::size_t

Definition at line 58 of file aligned_allocator.hpp.

◆ value_type

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
using tim::ert::aligned_allocator< Tp, AlignV >::value_type = Tp

Definition at line 53 of file aligned_allocator.hpp.

Constructor & Destructor Documentation

◆ aligned_allocator() [1/4]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
tim::ert::aligned_allocator< Tp, AlignV >::aligned_allocator ( )
default

◆ aligned_allocator() [2/4]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
tim::ert::aligned_allocator< Tp, AlignV >::aligned_allocator ( const aligned_allocator< Tp, AlignV > &  )
default

◆ aligned_allocator() [3/4]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
tim::ert::aligned_allocator< Tp, AlignV >::aligned_allocator ( aligned_allocator< Tp, AlignV > &&  )
inlinenoexcept

Definition at line 65 of file aligned_allocator.hpp.

65{}

◆ aligned_allocator() [4/4]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
template<typename U >
tim::ert::aligned_allocator< Tp, AlignV >::aligned_allocator ( const aligned_allocator< U, AlignV > &  )
inline

Definition at line 67 of file aligned_allocator.hpp.

68 {}

◆ ~aligned_allocator()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
tim::ert::aligned_allocator< Tp, AlignV >::~aligned_allocator ( )
default

Member Function Documentation

◆ address() [1/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
const Tp * tim::ert::aligned_allocator< Tp, AlignV >::address ( const Tp &  s) const
inline

Definition at line 80 of file aligned_allocator.hpp.

80{ return &s; }

◆ address() [2/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
Tp * tim::ert::aligned_allocator< Tp, AlignV >::address ( Tp &  r) const
inline

Definition at line 79 of file aligned_allocator.hpp.

79{ return &r; }

◆ allocate() [1/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
Tp * tim::ert::aligned_allocator< Tp, AlignV >::allocate ( const std::size_t  n) const
inline

Definition at line 109 of file aligned_allocator.hpp.

110 {
111 if(n == 0)
112 return nullptr;
113
114 // integer overflow check that throws std::length_error in case of overflow
115 if(n > max_size())
116 {
117 throw std::length_error(
118 "aligned_allocator<Tp>::allocate() - Integer overflow.");
119 }
120
121 // Mallocator wraps malloc().
122 void* const ptr = memory::allocate_aligned<Tp, device::cpu>(n, AlignV);
123
124 // throw std::bad_alloc in the case of memory allocation failure.
125 if(ptr == nullptr)
126 {
127 std::cerr << "Allocation of type " << typeid(Tp).name() << " of size " << n
128 << " and alignment " << AlignV << " failed. ptr = " << ptr
129 << std::endl;
130 throw std::bad_alloc();
131 }
132
133 return static_cast<Tp*>(ptr);
134 }

References tim::ert::aligned_allocator< Tp, AlignV >::max_size().

Referenced by tim::ert::aligned_allocator< Tp, AlignV >::allocate().

◆ allocate() [2/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
template<typename U >
Tp * tim::ert::aligned_allocator< Tp, AlignV >::allocate ( const std::size_t  n,
const U *   
) const
inline

Definition at line 143 of file aligned_allocator.hpp.

144 {
145 return allocate(n);
146 }
Tp * allocate(const std::size_t n) const

References tim::ert::aligned_allocator< Tp, AlignV >::allocate().

◆ construct() [1/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
template<typename... ArgsT>
void tim::ert::aligned_allocator< Tp, AlignV >::construct ( Tp *const  p,
ArgsT &&...  args 
) const
inline

Definition at line 102 of file aligned_allocator.hpp.

103 {
104 ::new((void*) p) Tp(std::forward<ArgsT>(args)...);
105 }

◆ construct() [2/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
void tim::ert::aligned_allocator< Tp, AlignV >::construct ( Tp *const  p,
const Tp &  t 
) const
inline

Definition at line 95 of file aligned_allocator.hpp.

96 {
97 void* const pv = static_cast<void*>(p);
98 new(pv) Tp(t);
99 }

◆ deallocate()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
void tim::ert::aligned_allocator< Tp, AlignV >::deallocate ( Tp *const  ptr,
const std::size_t   
) const
inline

Definition at line 136 of file aligned_allocator.hpp.

137 {
138 memory::free_aligned<Tp, device::cpu>(ptr);
139 }

◆ destroy()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
void tim::ert::aligned_allocator< Tp, AlignV >::destroy ( Tp *const  p) const
inline

Definition at line 107 of file aligned_allocator.hpp.

107{ p->~Tp(); }

◆ get_alignment()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
std::size_t tim::ert::aligned_allocator< Tp, AlignV >::get_alignment ( )
inline

Definition at line 149 of file aligned_allocator.hpp.

149{ return AlignV / 8; }

◆ max_size()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
std::size_t tim::ert::aligned_allocator< Tp, AlignV >::max_size ( ) const
inline

Definition at line 82 of file aligned_allocator.hpp.

83 {
84 // avoid signed/unsigned warnings independent of size_t definition
85 return (static_cast<std::size_t>(0) - static_cast<std::size_t>(1)) / sizeof(Tp);
86 }

Referenced by tim::ert::aligned_allocator< Tp, AlignV >::allocate().

◆ operator!=()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
bool tim::ert::aligned_allocator< Tp, AlignV >::operator!= ( const aligned_allocator< Tp, AlignV > &  other) const
inline

Definition at line 75 of file aligned_allocator.hpp.

75{ return !(*this == other); }

◆ operator=()

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
aligned_allocator & tim::ert::aligned_allocator< Tp, AlignV >::operator= ( const aligned_allocator< Tp, AlignV > &  )
delete

◆ operator==() [1/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
aligned_allocator & tim::ert::aligned_allocator< Tp, AlignV >::operator== ( aligned_allocator< Tp, AlignV > &&  )
delete

◆ operator==() [2/2]

template<typename Tp , std::size_t AlignV = 8 * sizeof(Tp)>
bool tim::ert::aligned_allocator< Tp, AlignV >::operator== ( const aligned_allocator< Tp, AlignV > &  ) const
inline

Definition at line 76 of file aligned_allocator.hpp.

76{ return true; }

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