Flow123d  JS_before_hm-1755-g6249b9fc1
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 }
internal::SimpleAllocator::rebind::other
SimpleAllocator< U > other
Definition: simple_allocator.hh:68
internal::SimpleAllocator::SimpleAllocator
SimpleAllocator(const SimpleAllocator &)
Definition: simple_allocator.hh:40
internal::SimpleAllocator::operator=
SimpleAllocator< T > & operator=(const SimpleAllocator &)
Definition: simple_allocator.hh:58
internal::SimpleAllocator::reference
T & reference
Definition: simple_allocator.hh:34
internal::SimpleAllocator::pointer
T * pointer
Definition: simple_allocator.hh:32
internal::SimpleAllocator
Definition: simple_allocator.hh:28
internal::SimpleAllocator::destroy
void destroy(pointer p)
Definition: simple_allocator.hh:62
internal::SimpleAllocator::value_type
T value_type
Definition: simple_allocator.hh:36
internal::SimpleAllocator::operator=
SimpleAllocator & operator=(const SimpleAllocator< U > &)
Definition: simple_allocator.hh:75
internal::SimpleAllocator::rebind
Definition: simple_allocator.hh:67
internal::SimpleAllocator::deallocate
void deallocate(void *p, size_type)
Definition: simple_allocator.hh:48
internal::SimpleAllocator::const_pointer
const typedef T * const_pointer
Definition: simple_allocator.hh:33
internal::SimpleAllocator::SimpleAllocator
SimpleAllocator(const SimpleAllocator< U > &)
Definition: simple_allocator.hh:72
internal::SimpleAllocator::construct
void construct(pointer p, const T &val)
Definition: simple_allocator.hh:60
internal::SimpleAllocator::difference_type
ptrdiff_t difference_type
Definition: simple_allocator.hh:31
internal::SimpleAllocator::max_size
size_type max_size() const
Definition: simple_allocator.hh:64
internal::SimpleAllocator::address
const_pointer address(const_reference x) const
Definition: simple_allocator.hh:56
internal::SimpleAllocator::const_reference
const typedef T & const_reference
Definition: simple_allocator.hh:35
internal::SimpleAllocator::allocate
pointer allocate(size_type n, const void *=0)
Definition: simple_allocator.hh:43
internal::SimpleAllocator::size_type
size_t size_type
Definition: simple_allocator.hh:30
internal
Definition: field_values.cc:20
internal::SimpleAllocator::SimpleAllocator
SimpleAllocator()
Definition: simple_allocator.hh:38
internal::SimpleAllocator::address
pointer address(reference x) const
Definition: simple_allocator.hh:54