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 &) 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 94 of file TestAlloc.h.

95  {
96  return &x;
97  }

◆ address() [2/2]

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

Definition at line 89 of file TestAlloc.h.

90  {
91  return &x;
92  }

◆ 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  // Suppress bogus warning seen with gcc 14.1.
74 #if __GNUC__ >= 14
75 # pragma GCC diagnostic push
76 # pragma GCC diagnostic ignored "-Wstringop-overflow"
77 #endif
78  new (p) T(std::forward<Args>(args)...);
79 #if __GNUC__ >= 14
80 # pragma GCC diagnostic pop
81 #endif
82  }

◆ 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 84 of file TestAlloc.h.

85  {
86  p->~T();
87  }

◆ 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 > &  ) const
inline

Definition at line 100 of file TestAlloc.h.

101  { return true; }

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
x
#define x
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:132
Athena_test::TestAlloc::pointer
T * pointer
Standard STL allocator typedefs.
Definition: TestAlloc.h:32
h
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35