CMS 3D CMS Logo

debugging_allocator.h
Go to the documentation of this file.
1 #ifndef DataFormatsCommonDebuggingAllocator
2 #define DataFormatsCommonDebuggingAllocator
3 
4 //---------------------------------------------------------------------
5 //
6 // This file declares and defines an allocator class template.
7 // This allocator is intended for use with the memory checking tool
8 // valgrind. It is a minimum conformant implementation which makes sure
9 // not use use any unitialized memory, and so it causes no spurious error
10 // reports from valgrind.
11 //
12 // The intended use is in the declarations of objects from STL templates,
13 // e.g.
14 // typedef vector<int, edm::debugging_allocator<int> > vint;
15 // etc.
16 //
17 //---------------------------------------------------------------------
18 
19 #include <limits>
20 #include <cstddef>
21 
22 namespace edm
23 {
24  template <class T>
26  {
27  public:
28  typedef size_t size_type;
29  typedef ptrdiff_t difference_type;
30  typedef T* pointer;
31  typedef T const* const_pointer;
32  typedef T& reference;
33  typedef T const& const_reference;
34  typedef T value_type;
35 
36  template <class U> struct rebind { typedef debugging_allocator<U> other; };
37 
38 
39  debugging_allocator() noexcept : dummy('x') { }
40 
41  debugging_allocator(debugging_allocator const&) noexcept : dummy('c') { }
42 
43  template <class U> debugging_allocator(debugging_allocator<U> const&) noexcept : dummy('u') { }
44 
45  ~debugging_allocator() noexcept { };
46 
47  pointer address(reference value) const {return &value;}
48 
50 
52 
53  pointer allocate(size_type num, void const* hint = 0)
54  {
55  // allocate objects with global new
56  return (pointer)(::operator new(num*sizeof(T)));
57  }
58 
59  void construct(pointer p, T const& value) { new((void*)p)T(value); }
60 
61  void destroy(pointer p) { p->~T(); }
62 
63  void deallocate(pointer p, size_type num) { ::operator delete((void*)p); }
64 
65  private:
66  char dummy;
67 
68  };
69 
70  // instances of all specializations of this allocator are equal
71  template <class X, class Y>
72  bool operator== (debugging_allocator<X> const&, debugging_allocator<Y> const&) noexcept { return true; }
73 
74  template <class X, class Y>
75  bool operator!= (debugging_allocator<X> const&, debugging_allocator<Y> const&) noexcept { return false; }
76 
77 } //namespace edm
78 
79 
80 #endif
edm::debugging_allocator::address
pointer address(reference value) const
Definition: debugging_allocator.h:47
edm::debugging_allocator::const_reference
T const & const_reference
Definition: debugging_allocator.h:33
edm::debugging_allocator::destroy
void destroy(pointer p)
Definition: debugging_allocator.h:61
edm::debugging_allocator::dummy
char dummy
Definition: debugging_allocator.h:66
edm::debugging_allocator::debugging_allocator
debugging_allocator(debugging_allocator< U > const &) noexcept
Definition: debugging_allocator.h:43
edm::debugging_allocator::pointer
T * pointer
Definition: debugging_allocator.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
edm::debugging_allocator::rebind
Definition: debugging_allocator.h:36
watchdog.const
const
Definition: watchdog.py:83
edm::debugging_allocator::reference
T & reference
Definition: debugging_allocator.h:32
Utilities.operator
operator
Definition: Utilities.py:24
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::debugging_allocator::value_type
T value_type
Definition: debugging_allocator.h:34
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::debugging_allocator::address
const_pointer address(const_reference value) const
Definition: debugging_allocator.h:49
edm::debugging_allocator::debugging_allocator
debugging_allocator() noexcept
Definition: debugging_allocator.h:39
edm::debugging_allocator::max_size
size_type max_size() const noexcept
Definition: debugging_allocator.h:51
edm::debugging_allocator::allocate
pointer allocate(size_type num, void const *hint=0)
Definition: debugging_allocator.h:53
edm::debugging_allocator::debugging_allocator
debugging_allocator(debugging_allocator const &) noexcept
Definition: debugging_allocator.h:41
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
edm::debugging_allocator::size_type
size_t size_type
Definition: debugging_allocator.h:28
value
Definition: value.py:1
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
edm::debugging_allocator::const_pointer
T const * const_pointer
Definition: debugging_allocator.h:31
edm::debugging_allocator::rebind::other
debugging_allocator< U > other
Definition: debugging_allocator.h:36
edm::debugging_allocator
Definition: debugging_allocator.h:25
T
long double T
Definition: Basic3DVectorLD.h:48
edm::debugging_allocator::construct
void construct(pointer p, T const &value)
Definition: debugging_allocator.h:59
edm::debugging_allocator::difference_type
ptrdiff_t difference_type
Definition: debugging_allocator.h:29
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::debugging_allocator::~debugging_allocator
~debugging_allocator() noexcept
Definition: debugging_allocator.h:45
dummy
Definition: DummySelector.h:38
edm::debugging_allocator::deallocate
void deallocate(pointer p, size_type num)
Definition: debugging_allocator.h:63