CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions
aligned_allocator< T, Alignment > Class Template Reference

#include <align_alloc.h>

Classes

struct  rebind
 

Public Types

typedef const Tconst_pointer
 
typedef const Tconst_reference
 
typedef ptrdiff_t difference_type
 
typedef Tpointer
 
typedef Treference
 
typedef std::size_t size_type
 
typedef T value_type
 

Public Member Functions

Taddress (T &r) const
 
const Taddress (const T &s) const
 
 aligned_allocator ()
 
 aligned_allocator (const aligned_allocator &)
 
template<typename U >
 aligned_allocator (const aligned_allocator< U, Alignment > &)
 
Tallocate (const std::size_t n) const
 
template<typename U >
Tallocate (const std::size_t n, const U *) const
 
void construct (T *const p, const T &t) const
 
void construct (T *const p)
 
void deallocate (T *const p, const std::size_t n) const
 
void destroy (T *const p) const
 
std::size_t max_size () const
 
bool operator!= (const aligned_allocator &other) const
 
bool operator== (const aligned_allocator &other) const
 
 ~aligned_allocator ()
 

Private Member Functions

aligned_allocatoroperator= (const aligned_allocator &)
 

Detailed Description

template<typename T, std::size_t Alignment>
class aligned_allocator< T, Alignment >

Allocator for aligned data.

Modified from the Mallocator from Stephan T. Lavavej. http://blogs.msdn.com/b/vcblog/archive/2008/08/28/the-mallocator.aspx

Definition at line 10 of file align_alloc.h.

Member Typedef Documentation

◆ const_pointer

template<typename T , std::size_t Alignment>
typedef const T* aligned_allocator< T, Alignment >::const_pointer

Definition at line 14 of file align_alloc.h.

◆ const_reference

template<typename T , std::size_t Alignment>
typedef const T& aligned_allocator< T, Alignment >::const_reference

Definition at line 16 of file align_alloc.h.

◆ difference_type

template<typename T , std::size_t Alignment>
typedef ptrdiff_t aligned_allocator< T, Alignment >::difference_type

Definition at line 19 of file align_alloc.h.

◆ pointer

template<typename T , std::size_t Alignment>
typedef T* aligned_allocator< T, Alignment >::pointer

Definition at line 13 of file align_alloc.h.

◆ reference

template<typename T , std::size_t Alignment>
typedef T& aligned_allocator< T, Alignment >::reference

Definition at line 15 of file align_alloc.h.

◆ size_type

template<typename T , std::size_t Alignment>
typedef std::size_t aligned_allocator< T, Alignment >::size_type

Definition at line 18 of file align_alloc.h.

◆ value_type

template<typename T , std::size_t Alignment>
typedef T aligned_allocator< T, Alignment >::value_type

Definition at line 17 of file align_alloc.h.

Constructor & Destructor Documentation

◆ aligned_allocator() [1/3]

template<typename T , std::size_t Alignment>
aligned_allocator< T, Alignment >::aligned_allocator ( )
inline

Definition at line 56 of file align_alloc.h.

56 {}

◆ aligned_allocator() [2/3]

template<typename T , std::size_t Alignment>
aligned_allocator< T, Alignment >::aligned_allocator ( const aligned_allocator< T, Alignment > &  )
inline

Definition at line 58 of file align_alloc.h.

58 {}

◆ aligned_allocator() [3/3]

template<typename T , std::size_t Alignment>
template<typename U >
aligned_allocator< T, Alignment >::aligned_allocator ( const aligned_allocator< U, Alignment > &  )
inline

Definition at line 61 of file align_alloc.h.

61 {}

◆ ~aligned_allocator()

template<typename T , std::size_t Alignment>
aligned_allocator< T, Alignment >::~aligned_allocator ( )
inline

Definition at line 63 of file align_alloc.h.

63 {}

Member Function Documentation

◆ address() [1/2]

template<typename T , std::size_t Alignment>
T* aligned_allocator< T, Alignment >::address ( T r) const
inline

Definition at line 21 of file align_alloc.h.

References alignCSCRings::r.

21 { return &r; }

◆ address() [2/2]

template<typename T , std::size_t Alignment>
const T* aligned_allocator< T, Alignment >::address ( const T s) const
inline

Definition at line 23 of file align_alloc.h.

References alignCSCRings::s.

23 { return &s; }

◆ allocate() [1/2]

template<typename T , std::size_t Alignment>
T* aligned_allocator< T, Alignment >::allocate ( const std::size_t  n) const
inline

Definition at line 66 of file align_alloc.h.

References aligned_alloc(), aligned_allocator< T, Alignment >::max_size(), dqmiodumpmetadata::n, NULL, and MetAnalyzer::pv().

Referenced by aligned_allocator< T, Alignment >::allocate().

66  {
67  // The return value of allocate(0) is unspecified.
68  // Mallocator returns NULL in order to avoid depending
69  // on malloc(0)'s implementation-defined behavior
70  // (the implementation can define malloc(0) to return NULL,
71  // in which case the bad_alloc check below would fire).
72  // All allocators can return NULL in this case.
73  if (n == 0) {
74  return NULL;
75  }
76 
77  // All allocators should contain an integer overflow check.
78  // The Standardization Committee recommends that std::length_error
79  // be thrown in the case of integer overflow.
80  if (n > max_size()) {
81  throw std::length_error("aligned_allocator<T>::allocate() - Integer overflow.");
82  }
83 
84  // Mallocator wraps malloc().
85  void* const pv = std::aligned_alloc(Alignment, n * sizeof(T));
86 
87  // Allocators should throw std::bad_alloc in the case of memory allocation failure.
88  if (pv == NULL) {
89  throw std::bad_alloc();
90  }
91 
92  return static_cast<T*>(pv);
93  }
#define NULL
Definition: scimark2.h:8
std::size_t max_size() const
Definition: align_alloc.h:25
def pv(vc)
Definition: MetAnalyzer.py:7
void * aligned_alloc(size_t alignment, size_t size) noexcept
long double T

◆ allocate() [2/2]

template<typename T , std::size_t Alignment>
template<typename U >
T* aligned_allocator< T, Alignment >::allocate ( const std::size_t  n,
const U *   
) const
inline

Definition at line 99 of file align_alloc.h.

References aligned_allocator< T, Alignment >::allocate(), and dqmiodumpmetadata::n.

99  {
100  return allocate(n);
101  }
T * allocate(const std::size_t n) const
Definition: align_alloc.h:66

◆ construct() [1/2]

template<typename T , std::size_t Alignment>
void aligned_allocator< T, Alignment >::construct ( T *const  p,
const T t 
) const
inline

Definition at line 39 of file align_alloc.h.

References AlCaHLTBitMon_ParallelJobs::p, MetAnalyzer::pv(), and submitPVValidationJobs::t.

39  {
40  void* const pv = static_cast<void*>(p);
41 
42  new (pv) T(t);
43  }
def pv(vc)
Definition: MetAnalyzer.py:7
long double T

◆ construct() [2/2]

template<typename T , std::size_t Alignment>
void aligned_allocator< T, Alignment >::construct ( T *const  p)
inline

◆ deallocate()

template<typename T , std::size_t Alignment>
void aligned_allocator< T, Alignment >::deallocate ( T *const  p,
const std::size_t  n 
) const
inline

Definition at line 95 of file align_alloc.h.

References free(), and AlCaHLTBitMon_ParallelJobs::p.

95 { std::free(p); }
void free(void *ptr) noexcept

◆ destroy()

template<typename T , std::size_t Alignment>
void aligned_allocator< T, Alignment >::destroy ( T *const  p) const
inline

Definition at line 47 of file align_alloc.h.

References AlCaHLTBitMon_ParallelJobs::p.

◆ max_size()

template<typename T , std::size_t Alignment>
std::size_t aligned_allocator< T, Alignment >::max_size ( ) const
inline

Definition at line 25 of file align_alloc.h.

Referenced by aligned_allocator< T, Alignment >::allocate().

25  {
26  // The following has been carefully written to be independent of
27  // the definition of size_t and to avoid signed/unsigned warnings.
28  return (static_cast<std::size_t>(0) - static_cast<std::size_t>(1)) / sizeof(T);
29  }
long double T

◆ operator!=()

template<typename T , std::size_t Alignment>
bool aligned_allocator< T, Alignment >::operator!= ( const aligned_allocator< T, Alignment > &  other) const
inline

Definition at line 37 of file align_alloc.h.

References trackingPlots::other.

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

◆ operator=()

template<typename T , std::size_t Alignment>
aligned_allocator& aligned_allocator< T, Alignment >::operator= ( const aligned_allocator< T, Alignment > &  )
private

◆ operator==()

template<typename T , std::size_t Alignment>
bool aligned_allocator< T, Alignment >::operator== ( const aligned_allocator< T, Alignment > &  other) const
inline

Definition at line 52 of file align_alloc.h.

52 { return true; }