ATLAS Offline Software
Loading...
Searching...
No Matches
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.
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

static constexpr 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 95 of file TestAlloc.h.

96 {
97 return &x;
98 }
To test handling of non-standard memory allocators.
Definition TestAlloc.h:29

◆ address() [2/2]

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

Definition at line 90 of file TestAlloc.h.

91 {
92 return &x;
93 }

◆ 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 if (!p) std::abort();
49 Head* h = (Head*)p;
50 h->i[0] = n;
51 h->i[1] = MAGIC;
52 return reinterpret_cast<pointer>(h+1);
53 }
T * pointer
Standard STL allocator typedefs.
Definition TestAlloc.h:32
static constexpr size_t MAGIC
Definition TestAlloc.h:40

◆ construct()

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

Definition at line 72 of file TestAlloc.h.

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

◆ deallocate()

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

Definition at line 55 of file TestAlloc.h.

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

◆ destroy()

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

Definition at line 85 of file TestAlloc.h.

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

◆ max_size()

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

Definition at line 66 of file TestAlloc.h.

67 {
68 return 99999;
69 }

◆ operator==()

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

Definition at line 101 of file TestAlloc.h.

102 { return true; }

Member Data Documentation

◆ MAGIC

template<class T>
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: