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 
40 
42 
43  template <class U> debugging_allocator(debugging_allocator<U> const&) noexcept : dummy('u') { }
44 
46 
47  pointer address(reference value) const {return &value;}
48 
49  const_pointer address(const_reference value) const {return &value; }
50 
51  size_type max_size() const noexcept { return std::numeric_limits<size_type>::max()/sizeof(T); }
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
void deallocate(pointer p, size_type num)
debugging_allocator(debugging_allocator const &) noexcept
const_pointer address(const_reference value) const
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: value.py:1
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
#define noexcept
pointer allocate(size_type num, void const *hint=0)
size_type max_size() const noexcept
HLT enums.
void construct(pointer p, T const &value)
debugging_allocator< U > other
long double T
debugging_allocator(debugging_allocator< U > const &) noexcept
pointer address(reference value) const