ATLAS Offline Software
TestAlloc.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef TESTTOOLS_TESTALLOC_H
14 #define TESTTOOLS_TESTALLOC_H
15 
16 
17 namespace Athena_test {
18 
19 
27 template <class T>
28 class TestAlloc
29 {
30 public:
32  typedef T* pointer;
33  typedef const T* const_pointer;
34  typedef T& reference;
35  typedef const T& const_reference;
36  typedef T value_type;
37  typedef size_t size_type;
38  typedef ptrdiff_t difference_type;
39 
40  constexpr static size_t MAGIC = 0xdeadbeeffeedabba;
41 
42  struct Head {
43  size_t i[2];
44  };
45  pointer allocate (size_type n, const void* = 0)
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  }
53 
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  }
64 
65  size_type max_size() const throw()
66  {
67  return 99999;
68  }
69 
70  template <class... Args>
71  void construct (pointer p, Args&&... args)
72  {
73  new (p) T(std::forward<Args>(args)...);
74  }
75 
76  void destroy (pointer p)
77  {
78  p->~T();
79  }
80 
82  {
83  return &x;
84  }
85 
87  {
88  return &x;
89  }
90 
91  bool operator== (const TestAlloc& other) const
92  { return this == &other; }
93  bool operator!= (const TestAlloc& other) const
94  { return this != &other; }
95 };
96 
97 
98 } // namespace Athena_test
99 
100 
101 #endif // not TESTTOOLS_TESTALLOC_H
Athena_test::TestAlloc::max_size
size_type max_size() const
Definition: TestAlloc.h:65
Athena_test::TestAlloc::MAGIC
constexpr static size_t MAGIC
Definition: TestAlloc.h:40
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
Athena_test::TestAlloc::destroy
void destroy(pointer p)
Definition: TestAlloc.h:76
Athena_test::TestAlloc::deallocate
void deallocate(pointer p, size_type n)
Definition: TestAlloc.h:54
Athena_test::TestAlloc::operator!=
bool operator!=(const TestAlloc &other) const
Definition: TestAlloc.h:93
Athena_test::TestAlloc::address
pointer address(reference x) const
Definition: TestAlloc.h:81
Athena_test::TestAlloc::Head::i
size_t i[2]
Definition: TestAlloc.h:43
Athena_test::TestAlloc::Head
Definition: TestAlloc.h:42
Athena_test::TestAlloc::const_pointer
const T * const_pointer
Definition: TestAlloc.h:33
Args
Definition: test_lwtnn_fastgraph.cxx:12
x
#define x
Athena_test::TestAlloc::size_type
size_t size_type
Definition: TestAlloc.h:37
beamspotman.n
n
Definition: beamspotman.py:731
extractSporadic.h
list h
Definition: extractSporadic.py:97
Athena_test
functions & macros to test the difference between floats
Definition: InitGaudiGoogleTest.h:30
Athena_test::TestAlloc
To test handling of non-standard memory allocators.
Definition: TestAlloc.h:29
TrigInDetValidation_Base.malloc
malloc
Definition: TrigInDetValidation_Base.py:129
Athena_test::TestAlloc::allocate
pointer allocate(size_type n, const void *=0)
Definition: TestAlloc.h:45
Athena_test::TestAlloc::value_type
T value_type
Definition: TestAlloc.h:36
Athena_test::TestAlloc::pointer
T * pointer
Standard STL allocator typedefs.
Definition: TestAlloc.h:32
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
h
Athena_test::TestAlloc::const_reference
const T & const_reference
Definition: TestAlloc.h:35
Athena_test::TestAlloc::difference_type
ptrdiff_t difference_type
Definition: TestAlloc.h:38
Athena_test::TestAlloc::reference
T & reference
Definition: TestAlloc.h:34
Athena_test::TestAlloc::construct
void construct(pointer p, Args &&... args)
Definition: TestAlloc.h:71
Athena_test::TestAlloc::operator==
bool operator==(const TestAlloc &other) const
Definition: TestAlloc.h:91
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
Athena_test::TestAlloc::address
const_pointer address(const_reference x) const
Definition: TestAlloc.h:86