CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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&) throw() : dummy('u') { }
44 
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&) throw() { return true; }
73 
74  template <class X, class Y>
75  bool operator!= (debugging_allocator<X> const&, debugging_allocator<Y> const&) throw() { return false; }
76 
77 } //namespace edm
78 
79 
80 #endif
void deallocate(pointer p, size_type num)
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
const_pointer address(const_reference value) const
debugging_allocator(debugging_allocator const &)
size_type max_size() const
const T & max(const T &a, const T &b)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
pointer allocate(size_type num, void const *hint=0)
debugging_allocator(debugging_allocator< U > const &)
void construct(pointer p, T const &value)
Definition: DDAxes.h:10
debugging_allocator< U > other
long double T
pointer address(reference value) const