Flow123d  DF_patch_fe_data_tables-b828b90
simple_allocator.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file simple_allocator.cc
15  * @ingroup system
16  * @brief Declaring internal allocator class which does not monitor memory
17  * consumption
18  */
19 
20 
21 namespace internal {
22 
23  /**
24  * Simple allocator which uses default malloc and free functions. Fields allocated
25  * with this allocator will not be included in overall memory consumption.
26  */
27  template<class T>
29  public:
30  typedef size_t size_type;
31  typedef ptrdiff_t difference_type;
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 
39 
41 
42 
43  pointer allocate(size_type n, const void * = 0) {
44  T *t = (T *) malloc(n * sizeof(T));
45  return t;
46  }
47 
48  void deallocate(void *p, size_type) {
49  if (p) {
50  free(p);
51  }
52  }
53 
54  pointer address(reference x) const { return &x; }
55 
56  const_pointer address(const_reference x) const { return &x; }
57 
58  SimpleAllocator<T> &operator=(const SimpleAllocator &) { return *this; }
59 
60  void construct(pointer p, const T &val) { new((T *) p) T(val); }
61 
62  void destroy(pointer p) { p->~T(); }
63 
64  size_type max_size() const { return size_t(-1); }
65 
66  template<class U>
67  struct rebind {
69  };
70 
71  template<class U>
73 
74  template<class U>
75  SimpleAllocator &operator=(const SimpleAllocator<U> &) { return *this; }
76  };
77 }
const_pointer address(const_reference x) const
pointer allocate(size_type n, const void *=0)
void construct(pointer p, const T &val)
SimpleAllocator(const SimpleAllocator &)
pointer address(reference x) const
SimpleAllocator(const SimpleAllocator< U > &)
SimpleAllocator & operator=(const SimpleAllocator< U > &)
size_type max_size() const
SimpleAllocator< T > & operator=(const SimpleAllocator &)
void deallocate(void *p, size_type)