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 // $Id: debugging_allocator.h,v 1.2 2008/01/17 20:26:23 wmtan Exp $
18 //---------------------------------------------------------------------
19 
20 #include <limits>
21 #include <cstddef>
22 
23 namespace edm
24 {
25  template <class T>
27  {
28  public:
29  typedef size_t size_type;
30  typedef ptrdiff_t difference_type;
31  typedef T* pointer;
32  typedef T const* const_pointer;
33  typedef T& reference;
34  typedef T const& const_reference;
35  typedef T value_type;
36 
37  template <class U> struct rebind { typedef debugging_allocator<U> other; };
38 
39 
41 
43 
44  template <class U> debugging_allocator(debugging_allocator<U> const&) throw() : dummy('u') { }
45 
47 
48  pointer address(reference value) const {return &value;}
49 
51 
53 
54  pointer allocate(size_type num, void const* hint = 0)
55  {
56  // allocate objects with global new
57  return (pointer)(::operator new(num*sizeof(T)));
58  }
59 
60  void construct(pointer p, T const& value) { new((void*)p)T(value); }
61 
62  void destroy(pointer p) { p->~T(); }
63 
64  void deallocate(pointer p, size_type num) { ::operator delete((void*)p); }
65 
66  private:
67  char dummy;
68 
69  };
70 
71  // instances of all specializations of this allocator are equal
72  template <class X, class Y>
73  bool operator== (debugging_allocator<X> const&, debugging_allocator<Y> const&) throw() { return true; }
74 
75  template <class X, class Y>
76  bool operator!= (debugging_allocator<X> const&, debugging_allocator<Y> const&) throw() { return false; }
77 
78 } //namespace edm
79 
80 
81 #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)
long long int num
Definition: procUtils.cc:71
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