ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
Athena_test::TestAlloc< T > Class Template Reference

To test handling of non-standard memory allocators. More...

#include <TestAlloc.h>

Collaboration diagram for Athena_test::TestAlloc< T >:

Classes

struct  Head
 

Public Types

typedef T * pointer
 Standard STL allocator typedefs. More...
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef T value_type
 
typedef size_t size_type
 
typedef ptrdiff_t difference_type
 

Public Member Functions

pointer allocate (size_type n, const void *=0)
 
void deallocate (pointer p, size_type n)
 
size_type max_size () const throw ()
 
template<class... Args>
void construct (pointer p, Args &&... args)
 
void destroy (pointer p)
 
pointer address (reference x) const
 
const_pointer address (const_reference x) const
 
bool operator== (const TestAlloc &other) const
 
bool operator!= (const TestAlloc &other) const
 

Static Public Attributes

constexpr static size_t MAGIC = 0xdeadbeeffeedabba
 

Detailed Description

template<class T>
class Athena_test::TestAlloc< T >

To test handling of non-standard memory allocators.

This is an allocator that adds a header to each block allocated, and then checks it on free. This ensures that the frees are matched with the allocations.

Definition at line 28 of file TestAlloc.h.

Member Typedef Documentation

◆ const_pointer

template<class T >
typedef const T* Athena_test::TestAlloc< T >::const_pointer

Definition at line 33 of file TestAlloc.h.

◆ const_reference

template<class T >
typedef const T& Athena_test::TestAlloc< T >::const_reference

Definition at line 35 of file TestAlloc.h.

◆ difference_type

template<class T >
typedef ptrdiff_t Athena_test::TestAlloc< T >::difference_type

Definition at line 38 of file TestAlloc.h.

◆ pointer

template<class T >
typedef T* Athena_test::TestAlloc< T >::pointer

Standard STL allocator typedefs.

Definition at line 32 of file TestAlloc.h.

◆ reference

template<class T >
typedef T& Athena_test::TestAlloc< T >::reference

Definition at line 34 of file TestAlloc.h.

◆ size_type

template<class T >
typedef size_t Athena_test::TestAlloc< T >::size_type

Definition at line 37 of file TestAlloc.h.

◆ value_type

template<class T >
typedef T Athena_test::TestAlloc< T >::value_type

Definition at line 36 of file TestAlloc.h.

Member Function Documentation

◆ address() [1/2]

template<class T >
const_pointer Athena_test::TestAlloc< T >::address ( const_reference  x) const
inline

Definition at line 86 of file TestAlloc.h.

87  {
88  return &x;
89  }

◆ address() [2/2]

template<class T >
pointer Athena_test::TestAlloc< T >::address ( reference  x) const
inline

Definition at line 81 of file TestAlloc.h.

82  {
83  return &x;
84  }

◆ allocate()

template<class T >
pointer Athena_test::TestAlloc< T >::allocate ( size_type  n,
const void *  = 0 
)
inline

Definition at line 45 of file TestAlloc.h.

46  {
47  void* p = malloc (sizeof(Head) + n*sizeof(T));
48  Head* h = (Head*)p;
49  h->i[0] = n;
50  h->i[1] = MAGIC;
51  return (pointer)(h+1);
52  }

◆ construct()

template<class T >
template<class... Args>
void Athena_test::TestAlloc< T >::construct ( pointer  p,
Args &&...  args 
)
inline

Definition at line 71 of file TestAlloc.h.

72  {
73  new (p) T(std::forward<Args>(args)...);
74  }

◆ deallocate()

template<class T >
void Athena_test::TestAlloc< T >::deallocate ( pointer  p,
size_type  n 
)
inline

Definition at line 54 of file TestAlloc.h.

55  {
56  Head* h = (Head*)p;
57  --h;
58  if (h->i[0] != n ||
59  h->i[1] != MAGIC) {
60  std::abort();
61  }
62  free (h);
63  }

◆ destroy()

template<class T >
void Athena_test::TestAlloc< T >::destroy ( pointer  p)
inline

Definition at line 76 of file TestAlloc.h.

77  {
78  p->~T();
79  }

◆ max_size()

template<class T >
size_type Athena_test::TestAlloc< T >::max_size ( ) const
throw (
)
inline

Definition at line 65 of file TestAlloc.h.

66  {
67  return 99999;
68  }

◆ operator!=()

template<class T >
bool Athena_test::TestAlloc< T >::operator!= ( const TestAlloc< T > &  other) const
inline

Definition at line 93 of file TestAlloc.h.

94  { return this != &other; }

◆ operator==()

template<class T >
bool Athena_test::TestAlloc< T >::operator== ( const TestAlloc< T > &  other) const
inline

Definition at line 91 of file TestAlloc.h.

92  { return this == &other; }

Member Data Documentation

◆ MAGIC

template<class T >
constexpr static size_t Athena_test::TestAlloc< T >::MAGIC = 0xdeadbeeffeedabba
staticconstexpr

Definition at line 40 of file TestAlloc.h.


The documentation for this class was generated from the following file:
Athena_test::TestAlloc::MAGIC
constexpr static size_t MAGIC
Definition: TestAlloc.h:40
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
x
#define x
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:129
Athena_test::TestAlloc::pointer
T * pointer
Standard STL allocator typedefs.
Definition: TestAlloc.h:32
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
h
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35