utilities  0.0
memory.h
Go to the documentation of this file.
1 #ifndef MOLPRO_MEMORY_H
2 #define MOLPRO_MEMORY_H
3 #include <cstddef>
4 #include <cstdint>
5 #include <sstream>
6 #include <iostream>
7 #include <limits>
8 #include <string>
9 #include <unordered_map>
10 #include <new>
11 #include <vector>
12 #include <array>
13 #include <stdexcept>
14 #include <cassert> // assumed that NDEBUG is set properly for optimised compilation
15 #include <iostream>
16 #include <iterator>
17 #include <algorithm>
18 #include <initializer_list>
19 #ifdef __cplusplus
20 #include <climits>
21 #endif
22 #include <limits>
24 
25 #ifdef MOLPRO_MEMORY_FORTRAN
26 extern "C" {
32 void memory_initialize(char *buffer, size_t n);
38 double* memory_allocate(size_t n);
47 void memory_release(char* p, int all = 1);
58 void memory_resize(char** p, size_t n);
64 size_t memory_save();
70 void memory_release_saved(size_t p);
77 size_t memory_used(int maximum);
82 size_t memory_remaining();
86 void memory_print_status();
93 void memory_reset_maximum_stack(int64_t level);
94 
95 void memory_module_test_fortran(int printlevel);
96 
97 }
98 
99 #else // MOLPRO_MEMORY_FORTRAN
100 extern size_t _private_memory_used;
102 extern std::unordered_map<char*, size_t> _private_memory_lengths;
103 
104 inline size_t memory_initialize(char *buffer, size_t max) {
106 } // more checks
113 inline size_t memory_used(int maximum = 0) { return _private_memory_used; }
122 inline void memory_print_status() {
123  std::cout << "Memory used: " << memory_used() << std::endl;
124  std::cout << "Memory remaining: " << memory_remaining() << std::endl;
125 }
132 inline void memory_reset_maximum_stack(int64_t level) {
133 
134 }
135 #endif // MOLPRO_MEMORY_FORTRAN
136 
137 namespace molpro {
143 template<typename T, typename A = std::allocator<T> >
144 class allocator_ : public A {
145  using a_t = std::allocator_traits<A>;
146  public :
147 // using A::A;
148  typedef T value_type;
149  typedef value_type* pointer;
150  typedef const value_type* const_pointer;
152  typedef const value_type& const_reference;
153  typedef std::size_t size_type;
154  typedef std::ptrdiff_t difference_type;
155 
156  public :
157  template<typename U>
158  struct rebind {
160  };
161 
162  public :
163 
164  pointer address(reference r) { return &r; }
165  const_pointer address(const_reference r) const { return &r; }
166 
167 #ifndef NOALLOCATE
168  pointer allocate(size_type cnt, typename std::allocator<void>::const_pointer = nullptr) {
169 #ifdef MOLPRO_MEMORY_FORTRAN
170  if (memory_remaining() < cnt * sizeof(T))
171 #else
172  // std::cout << "hello from allocate" << std::endl;
173  if (_private_memory_maximum_allocatable == 0) _private_memory_maximum_allocatable = memory_initialize(nullptr, std::numeric_limits<size_t>::max());
174  if ((_private_memory_maximum_allocatable - _private_memory_used) < (cnt * sizeof(T)))
175 #endif
176  throw std::runtime_error(std::string("molpro::allocate: insufficient remaining stack memory; remaining=")
177  + std::to_string(static_cast<unsigned long long>(memory_remaining()))
178  + std::string(", requested=")
179  + std::to_string(static_cast<unsigned long long>(cnt * sizeof(T))));
180 #ifdef MOLPRO_MEMORY_FORTRAN
181  return reinterpret_cast<pointer>(memory_allocate(cnt * sizeof(T)));
182 #else
183  _private_memory_used += cnt * sizeof(T);
184 // std::cout << "incrementing used by " << cnt * sizeof(T) << " to " << _private_memory_used << std::endl;
185 #ifdef MEMORY_MALLOC
186  auto result = reinterpret_cast<pointer>( malloc(cnt * sizeof (T)));
187 #else
188  void* pp = ::operator new[](cnt * sizeof(T));
189  auto result = reinterpret_cast<pointer>( pp);
190 #endif
191  _private_memory_lengths[reinterpret_cast<char*>(result)] = cnt * sizeof(T);
192  return result;
193 #endif
194  }
195 
197 #ifdef MOLPRO_MEMORY_FORTRAN
198  memory_release((char*) p, 0);
199 #else
200  _private_memory_used -= _private_memory_lengths[reinterpret_cast<char*>(p)];
201 // std::cout << "decrementing used to " << _private_memory_used << std::endl;
202  _private_memory_lengths.erase(reinterpret_cast<char*>(p));
203 #ifdef MEMORY_MALLOC
204  free(reinterpret_cast<char*>(p));
205 #else
206  delete[] reinterpret_cast<char*>(p);
207 #endif
208 #endif
209  }
210 #endif
211 
212  size_type max_size() const {
213  return std::numeric_limits<size_type>::max();
214  }
215 
216 // void construct(pointer p, const T& t) { new(p) T(t); }
217 // void destroy(pointer p) { p->~T(); }
218  template<typename U>
219  void construct(U* ptr)
220  noexcept(std::is_nothrow_default_constructible<U>::value) {
221  ::new(static_cast<void*>(ptr)) U; // no initialisation
222  }
223  template<typename U, typename...Args>
224  void construct(U* ptr, Args&& ... args) {
225  a_t::construct(static_cast<A&>(*this),
226  ptr, std::forward<Args>(args)...);
227  }
228 
229  bool operator==(allocator_ const&) { return true; }
230  bool operator!=(allocator_ const& a) { return !operator==(a); }
231 };
232 template<typename T>
234 }
235 
236 namespace molpro {
237 
238 template<typename T=double, typename A=molpro::allocator<T> >
239 using stdvector = std::vector<T, A>;
240 
272 template<typename T=double, typename _Alloc=molpro::allocator<T>>
274 public:
275  pointer_holder(T* const ptr) : m_ptr(ptr) {}
276  T* m_ptr;
277 };
278 template<typename T=double, typename _Alloc=molpro::allocator<T>>
279 class vector {
280 /* The _Alloc template argument is provided to let molpro::vector have
281  the same signature as std::vector. They must have same signature if you
282  want a templated container (ie allowing use of std::vector OR molpro::vector)
283  when using ifort15. See bug 5299.
284 */
285  private:
286  std::vector<T, _Alloc> m_stdvector; // managed buffer
287  T* m_buffer; // pointer to the buffer TODO maybe not needed
288 
289  public:
290 // vector<T, _Alloc>() : m_stdvector(), m_buffer(m_stdvector.data()) { }
295  vector<T, _Alloc>(size_t const length = 0)
296  : m_stdvector(length), m_buffer(m_stdvector.data()) {}
297 
303  vector<T, _Alloc>(size_t const length, const T& value)
304  : m_stdvector(length, value), m_buffer(m_stdvector.data()) {}
305 
311  template<class InputIterator>
312  vector<T, _Alloc>(InputIterator first, InputIterator last)
313  : m_stdvector(first, last), m_buffer(m_stdvector.data()) {}
314 
319  vector<T, _Alloc>(std::initializer_list<T> il) : m_stdvector(il), m_buffer(m_stdvector.data()) {}
320 
325  vector<T, _Alloc>(const vector<T, _Alloc>& source) {
326  m_stdvector.insert(m_stdvector.begin(), source.begin(), source.end());
327  m_buffer = m_stdvector.data();
328  }
329 
334  if (&copy == this) return *this;
335  resize(copy.size());
336  std::copy(copy.begin(), copy.end(), this->begin());
337  return *this;
338  }
339 
340  virtual ~vector() = default;
341 
342  T& operator[](size_t n) {
343  return m_stdvector[n];
344  }
345  const T& operator[](size_t n) const {
346  return m_stdvector[n];
347  }
353  template<class InputIterator>
354  void assign(InputIterator first, InputIterator last) {
355  if (last - first != m_stdvector.size()) resize(last - first);
356  std::copy(first, last, begin());
357  }
362  void assign(const T& value) {
363  std::fill(begin(), end(), value);
364  }
370  void assign(size_t n, const T& value) {
371  m_stdvector.assign(n, value);
372  }
377  void assign(std::initializer_list<T> il) {
378  m_stdvector.assign(il);
379  }
380 
381  T& at(size_t n) {
382  return m_stdvector.at(n);
383  }
384 
385  const T& at(size_t n) const {
386  return m_stdvector.at(n);
387  }
388 
389  T& back() noexcept {
390  return m_stdvector.back();
391  }
392 
393  const T& back() const noexcept {
394  return m_stdvector.back();
395  }
396 
397  size_t capacity() const noexcept {
398  return m_stdvector.capacity();
399  }
400 
401  void clear() noexcept {
402  m_stdvector.clear();
403  }
404 
405  bool empty() const noexcept {
406  return m_stdvector.empty();
407  }
408 
409  T& front() noexcept {
410  return m_stdvector.front();
411  }
412 
413  const T& front() const noexcept {
414  return m_stdvector.front();
415  }
416 
417  T* data() noexcept { return &front(); }
418  const T* data() const noexcept { return m_stdvector.data(); }
419 
420  size_t max_size() const noexcept {
421  return m_stdvector.max_size();
422  }
423 
424  size_t size() const noexcept {
425  return m_stdvector.size();
426  }
427 
432  void swap(vector<T, _Alloc>& x) { swap(*this, x); }
433 
435  std::swap(a.m_stdvector, b.m_stdvector);
436  }
437 
438  template <bool IsConst>
439  class MyIterator : public pointer_holder<T,_Alloc> {
440  public:
441  using iterator_category = std::forward_iterator_tag;
442  using value_type = T;
443  using difference_type = std::ptrdiff_t;
444  using pointer = T*;
445  using reference = T&;
446  MyIterator() noexcept : pointer_holder<T>(nullptr) {}
448  MyIterator(const MyIterator&) = default;
449  template<bool IsConst_ = IsConst, class = std::enable_if_t<IsConst_>>
451 
452  reference operator*() const noexcept { return *(this->m_ptr); }
453  pointer operator->() const noexcept { return (this->m_ptr); }
454  MyIterator& operator++() {(this->m_ptr)++; return *this; }
455  MyIterator operator++(int) {MyIterator tmp = *this; ++(*this); return tmp; }
456  MyIterator& operator--() {(this->m_ptr)--; return *this; }
457  MyIterator operator--(int) {MyIterator tmp = *this; --(*this); return tmp; }
458  MyIterator& operator+=(difference_type n) {(this->m_ptr) += n; return *this; }
459  MyIterator& operator-=(difference_type n) {(this->m_ptr) -= n; return *this; }
460  friend MyIterator operator+(difference_type n, const MyIterator& rhs) {MyIterator tmp(rhs); return tmp += n; }
461  friend MyIterator operator+( const MyIterator& rhs,difference_type n) {MyIterator tmp(rhs); return tmp += n; }
462  friend MyIterator operator-(difference_type n, const MyIterator& rhs) {MyIterator tmp(rhs); return tmp -= n; }
463  friend MyIterator operator-( const MyIterator& rhs,difference_type n) {MyIterator tmp(rhs); return tmp -= n; }
464  friend bool operator==(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr == rhs.m_ptr;}
465  friend bool operator!=(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr != rhs.m_ptr;}
466  friend bool operator<(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr < rhs.m_ptr;}
467  friend bool operator>(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr > rhs.m_ptr;}
468  friend bool operator<=(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr <= rhs.m_ptr;}
469  friend bool operator>=(const MyIterator& lhs, const MyIterator& rhs) { return lhs.m_ptr >= rhs.m_ptr; }
470  friend class MyIterator<true>;
471  friend class MyIterator<false>;
472  // friend MyIterator erase(MyIterator first, MyIterator last) ;
473  // friend MyIterator erase(MyIterator pos) ;
474  // private:
475  // pointer m_ptr;
476  };
477 
480 
483 
484  iterator begin() noexcept { return iterator(m_buffer); }
485  const_iterator begin() const noexcept { return cbegin(); }
486  const_iterator cbegin() const noexcept { return const_iterator(m_buffer); }
487 
488  iterator end() noexcept { return m_buffer + size(); }
489  const_iterator end() const noexcept { return cend(); }
490  const_iterator cend() const noexcept { return const_iterator(m_buffer + size()); }
491 
492  using reverse_iterator = std::reverse_iterator<Iterator>;
493  using const_reverse_iterator = std::reverse_iterator<ConstIterator>;
494  reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
495  const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
497  reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
498  const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
499  const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cend()); }
500 
502  return &(*m_stdvector.erase(m_stdvector.begin() + (&(*pos) - data())));
503  }
504 
506  return &(*m_stdvector.erase(m_stdvector.begin() + (&(*first) - data()),
507  m_stdvector.begin() + (&(*last) - data())));
508  }
509 
516  std::string str(int verbosity = 1, unsigned int columns = UINT_MAX) const {
517  std::ostringstream s;
518  if (verbosity == 0)
519  s << size();
520  else if (verbosity > 0) {
521  for (size_t i = 0; i < size(); i++) {
522  if (i > 0) {
523  if (i % columns)
524  s << " ";
525  else
526  s << std::endl;
527  }
528  s << at(i);
529  }
530  }
531  return s.str();
532  }
533 
534  void reserve(size_t new_cap) {
535  m_stdvector.reserve(new_cap);
536  m_buffer = m_stdvector.data();
537  }
538 
543  void resize(size_t n) {
544  m_stdvector.resize(n);
545  m_buffer = m_stdvector.data();
546  }
547 
553  void resize(size_t n, const T& val) {
554  m_stdvector.resize(n, val);
555  m_buffer = m_stdvector.data();
556  }
557 
558  void shrink_to_fit() {
559  m_stdvector.shrink_to_fit();
560  m_buffer = m_stdvector.data();
561  }
562 
563  void pop_back() {
564  m_stdvector.pop_back();
565  }
566 
567  void push_back(const T& value) {
568  m_stdvector.push_back(value);
569  m_buffer = m_stdvector.data();
570  }
571 
572  void push_back(T&& value) {
573  m_stdvector.push_back(std::forward<T>(value));
574  m_buffer = m_stdvector.data();
575  }
576 
577  template<class... Args>
578  void emplace_back(Args&& ... args) {
579  m_stdvector.emplace_back(std::forward<Args>(args)...);
580  m_buffer = m_stdvector.data();
581  }
582 
583  template<class... Args>
584  iterator emplace(const_iterator pos, Args&& ... args) {
585  m_stdvector.emplace(pos, std::forward<Args>(args)...);
586  m_buffer = m_stdvector.data();
587  }
588 
589 };
590 template<class T, typename _Alloc>
591 std::ostream& operator<<(std::ostream& os, vector<T, _Alloc> const& obj) {
592  return os << obj.str();
593 }
594 
595 template<typename T=double, typename _Alloc=molpro::allocator<T>>
596 std::ptrdiff_t operator-(const pointer_holder<T>& a,
597  const pointer_holder<T>& b)
598 {
599  return a.m_ptr - b.m_ptr;
600 }
601 
602 template <typename T, typename _Alloc>
604  int increment)
605 {
606  auto result = vector<T, _Alloc>::Iterator(a);
607  result += increment;
608  return result;
609 }
610 
611 template <typename T, typename _Alloc>
613  int increment)
614 {
615  auto result = vector<T, _Alloc>::Iterator(a);
616  result -= increment;
617  return result;
618 }
619 
620 
621 
665 template<typename T=double>
666 class array {
667 /* The _Alloc template argument is only provided to let molpro::array have
668  the same signature as std::array. They must have same signature if you
669  want a templated container (ie allowing use of std::array OR molpro::array)
670  when using ifort15. See bug 5299. // TODO consider this
671 */
672  private:
673  allocator<T> m_allocator;
674  size_t m_length; // length of unmanaged buffer, or zero to signal managed buffer
675  bool m_owned; // if the data is owned by this object rather than mapped
676  T* m_buffer; // pointer to the buffer
677 
678  public:
683  explicit array<T>(size_t const length = 0)
684  : m_allocator(), m_length(length), m_owned(true)
685 // , m_buffer(reinterpret_cast<T*>(new void*[length * sizeof(T)]))
686  , m_buffer(m_allocator.allocate(length)) {
687 // std::cout << "construct molpro::array"<<length<<std::endl;
688  }
689 
695  array<T>(size_t const length, const T& value)
696  : m_allocator(), m_length(length), m_owned(true), m_buffer(m_allocator.allocate(length)) { assign(value); }
697 
703  template<class InputIterator>
704  array<T>(InputIterator
705  first,
706  InputIterator last
707  )
708  : m_allocator(), m_length(last - first), m_buffer(m_allocator.allocate(last - first)), m_owned(true) {}
709 
714  array<T>(std::initializer_list<T>
715  il)
716  : m_allocator(), m_length(il.size()),
717  m_buffer(m_allocator.allocate(il.size())), m_owned(true) { std::copy(il.begin(), il.end(), begin()); }
718 
724  array<T>(T* const buffer, size_t const length)
725  :
726  m_length(length), m_owned(false), m_buffer(buffer) {}
727 
732  template<std::size_t N>
733  explicit array<T>(std::array<T, N>& array)
734  : m_length(array.size()), m_owned(false), m_buffer(array.data()) {}
735 
740  explicit array<T>(std::vector<T>& array)
741  : m_length(array.size()), m_owned(false), m_buffer(array.data()) {}
742 
747  array<T>(const array<T>& source)
748  : m_allocator(), m_length(source.size()), m_owned(true), m_buffer(m_allocator.allocate(source.size())) {
749  std::copy(source.begin(), source.end(), begin());
750  }
751 
755  array<T>& operator=(const array<T>& copy) {
756  if (&copy == this) return *this;
757  if (copy.size() != m_length) throw std::runtime_error("Unequal length copy not supported");
758  std::copy(copy.begin(), copy.end(), this->begin());
759  return *this;
760  }
761 
762  virtual ~array() {
763  if (m_owned) m_allocator.deallocate(m_buffer, m_length);
764  }
765 
766  T& operator[](size_t n) {
767  assert(m_length == 0 || (n <= m_length));
768  return m_buffer[n];
769  }
770  const T& operator[](size_t n) const {
771  assert(m_length == 0 || (n <= m_length));
772  return m_buffer[n];
773  }
779  template<class InputIterator>
780  void assign(InputIterator first, InputIterator last) {
781  if (last - first != m_length) throw std::runtime_error("Unequal lengths in copy");
782  std::copy(first, last, begin());
783  }
788  void assign(const T& value) {
789  std::fill(begin(), end(), value);
790  }
796  void assign(size_t n, const T& value) {
797  {
798  if (n != m_length) throw std::runtime_error("Unequal lengths in copy");
799  assign(value);
800  }
801  }
806  void assign(std::initializer_list<T> il) {
807  if (il.size() != m_length) throw std::runtime_error("Unequal lengths in copy");
808  std::copy(il.begin(), il.end(), begin());
809  }
810 
811  T& at(size_t n) {
812  if (n < m_length) return m_buffer[n]; else throw std::out_of_range("array::at() out of range");
813  }
814 
815  const T& at(size_t n) const {
816  if (n < m_length) return m_buffer[n]; else throw std::out_of_range("array::at() out of range");
817  }
818 
819  T& back() noexcept {
820  return m_buffer[size() - 1];
821  }
822 
823  const T& back() const noexcept {
824  return m_buffer[size() - 1];
825  }
826 
827  bool empty() const noexcept {
828  return m_length == 0;
829  }
830 
831  T& front() noexcept {
832  return m_buffer[0];
833  }
834 
835  const T& front() const noexcept {
836  return m_buffer[0];
837  }
838 
839  T* data() noexcept { return &front(); }
840  const T* data() const noexcept { return m_buffer; }
841 
842  size_t max_size() const noexcept {
843  return m_length;
844  }
845 
846  size_t size() const noexcept {
847  return m_length;
848  }
849 
854  void swap(array<T>& x) { swap(*this, x); }
855 
856  friend void swap(array<T>& a, array<T>& b) {
857  std::swap(a.m_buffer, b.m_buffer);
858  std::swap(a.m_length, b.m_length);
859  std::swap(a.m_owned, b.m_owned);
860  }
861 
862  template <bool IsConst>
863  class MyIterator {
864  public:
865  using iterator_category = std::forward_iterator_tag;
866  using value_type = T;
867  using difference_type = std::ptrdiff_t;
868  using pointer = T*;
869  using reference = T&;
870  MyIterator() noexcept : m_ptr(nullptr) {}
871  MyIterator(pointer ptr) : m_ptr(ptr) {}
872  MyIterator(const MyIterator&) = default;
873  template<bool IsConst_ = IsConst, class = std::enable_if_t<IsConst_>>
874  MyIterator(const MyIterator<false>& rhs) : m_ptr(rhs.m_ptr) {}
875 
876  reference operator*() const noexcept { return *m_ptr; }
877  pointer operator->() const noexcept { return m_ptr; }
878  MyIterator& operator++() {m_ptr++; return *this; }
879  MyIterator operator++(int) {MyIterator tmp = *this; ++(*this); return tmp; }
880  MyIterator& operator--() {m_ptr--; return *this; }
881  MyIterator operator--(int) {MyIterator tmp = *this; --(*this); return tmp; }
882  friend bool operator==(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr == rhs.m_ptr;}
883  friend bool operator!=(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr != rhs.m_ptr;}
884  friend bool operator<(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr < rhs.m_ptr;}
885  friend bool operator>(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr > rhs.m_ptr;}
886  friend bool operator<=(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr <= rhs.m_ptr;}
887  friend bool operator>=(const MyIterator& lhs, const MyIterator& rhs) {return lhs.m_ptr >= rhs.m_ptr;}
888  friend class MyIterator<true>;
889  friend class MyIterator<false>;
890  private:
891  pointer m_ptr;
892  };
893 
896 
899 
900  iterator begin() noexcept { return iterator(m_buffer); }
901  const_iterator begin() const noexcept { return cbegin(); }
902  const_iterator cbegin() const noexcept { return const_iterator(m_buffer); }
903 
904  iterator end() noexcept { return m_buffer + size(); }
905  const_iterator end() const noexcept { return cend(); }
906  const_iterator cend() const noexcept { return const_iterator(m_buffer + size()); }
907 
908  using reverse_iterator = std::reverse_iterator<Iterator>;
909  using const_reverse_iterator = std::reverse_iterator<ConstIterator>;
910  reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
911  const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(end()); }
913  reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
914  const_reverse_iterator rend() const noexcept { return const_reverse_iterator(begin()); }
915  const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cend()); }
916 
917 
924  std::string str(int verbosity = 1, unsigned int columns = UINT_MAX) const {
925  std::ostringstream s;
926  if (verbosity == 0)
927  s << size();
928  else if (verbosity > 0) {
929  for (size_t i = 0; i < size(); i++) {
930  if (i > 0) {
931  if (i % columns)
932  s << " ";
933  else
934  s << std::endl;
935  }
936  s << at(i);
937  }
938  }
939  return s.str();
940  }
941 };
942 
943 template<class T>
944 std::ostream& operator<<(std::ostream& os, array<T> const& obj) {
945  return os << obj.str();
946 }
947 
948 }
949 
950 #endif
Definition: memory.h:144
size_type max_size() const
Definition: memory.h:212
value_type & reference
Definition: memory.h:151
value_type * pointer
Definition: memory.h:149
pointer address(reference r)
Definition: memory.h:164
void deallocate(pointer p, size_type)
Definition: memory.h:196
std::ptrdiff_t difference_type
Definition: memory.h:154
std::size_t size_type
Definition: memory.h:153
bool operator==(allocator_ const &)
Definition: memory.h:229
const value_type * const_pointer
Definition: memory.h:150
void construct(U *ptr) noexcept(std::is_nothrow_default_constructible< U >::value)
Definition: memory.h:219
const_pointer address(const_reference r) const
Definition: memory.h:165
T value_type
Definition: memory.h:148
const value_type & const_reference
Definition: memory.h:152
bool operator!=(allocator_ const &a)
Definition: memory.h:230
pointer allocate(size_type cnt, typename std::allocator< void >::const_pointer=nullptr)
Definition: memory.h:168
void construct(U *ptr, Args &&... args)
Definition: memory.h:224
Definition: memory.h:863
std::forward_iterator_tag iterator_category
Definition: memory.h:865
MyIterator operator++(int)
Definition: memory.h:879
MyIterator & operator++()
Definition: memory.h:878
MyIterator & operator--()
Definition: memory.h:880
friend bool operator<=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:886
T & reference
Definition: memory.h:869
friend bool operator>(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:885
T * pointer
Definition: memory.h:868
friend bool operator>=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:887
T value_type
Definition: memory.h:866
pointer operator->() const noexcept
Definition: memory.h:877
MyIterator(const MyIterator< false > &rhs)
Definition: memory.h:874
reference operator*() const noexcept
Definition: memory.h:876
MyIterator(pointer ptr)
Definition: memory.h:871
MyIterator() noexcept
Definition: memory.h:870
std::ptrdiff_t difference_type
Definition: memory.h:867
friend bool operator==(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:882
friend bool operator!=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:883
MyIterator(const MyIterator &)=default
friend bool operator<(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:884
MyIterator operator--(int)
Definition: memory.h:881
A template for a container class like std::array<T> but with the following features.
Definition: memory.h:666
iterator begin() noexcept
Definition: memory.h:900
const T & operator[](size_t n) const
Definition: memory.h:770
const_iterator cend() const noexcept
Definition: memory.h:906
const_reverse_iterator crend() const noexcept
Definition: memory.h:915
std::reverse_iterator< Iterator > reverse_iterator
Definition: memory.h:908
void assign(InputIterator first, InputIterator last)
Assign new contents to the array, replacing its current contents.
Definition: memory.h:780
T & back() noexcept
Definition: memory.h:819
const_iterator begin() const noexcept
Definition: memory.h:901
void swap(array< T > &x)
Exchange the content of the container by the content of x, which is another object of the same type.
Definition: memory.h:854
friend void swap(array< T > &a, array< T > &b)
Definition: memory.h:856
std::string str(int verbosity=1, unsigned int columns=UINT_MAX) const
Generate a printable representation of the object.
Definition: memory.h:924
reverse_iterator rbegin() noexcept
Definition: memory.h:910
const T * data() const noexcept
Definition: memory.h:840
virtual ~array()
Definition: memory.h:762
std::reverse_iterator< ConstIterator > const_reverse_iterator
Definition: memory.h:909
size_t size() const noexcept
Definition: memory.h:846
const_iterator end() const noexcept
Definition: memory.h:905
T & at(size_t n)
Definition: memory.h:811
array< T > & operator=(const array< T > &copy)
Copy assignment operator.
Definition: memory.h:755
const_iterator cbegin() const noexcept
Definition: memory.h:902
void assign(const T &value)
Assign new contents to the array, replacing its current contents.
Definition: memory.h:788
iterator end() noexcept
Definition: memory.h:904
T * data() noexcept
Definition: memory.h:839
const T & front() const noexcept
Definition: memory.h:835
reverse_iterator rend() noexcept
Definition: memory.h:913
const T & back() const noexcept
Definition: memory.h:823
T & front() noexcept
Definition: memory.h:831
Iterator iterator
Definition: memory.h:897
void assign(size_t n, const T &value)
Assign new contents to the array, replacing its current contents.
Definition: memory.h:796
ConstIterator const_iterator
Definition: memory.h:898
const T & at(size_t n) const
Definition: memory.h:815
void assign(std::initializer_list< T > il)
Assign new contents to the array, replacing its current contents.
Definition: memory.h:806
array(size_t const length=0)
Construct an array of type T with managed storage.
Definition: memory.h:683
T & operator[](size_t n)
Definition: memory.h:766
const_reverse_iterator rbegin() const noexcept
Definition: memory.h:911
const_reverse_iterator crbegin() const noexcept
Definition: memory.h:912
bool empty() const noexcept
Definition: memory.h:827
const_reverse_iterator rend() const noexcept
Definition: memory.h:914
size_t max_size() const noexcept
Definition: memory.h:842
A template for a container class like std::vector<T> but with the following features.
Definition: memory.h:273
pointer_holder(T *const ptr)
Definition: memory.h:275
T * m_ptr
Definition: memory.h:276
Definition: memory.h:439
T value_type
Definition: memory.h:442
friend MyIterator operator+(const MyIterator &rhs, difference_type n)
Definition: memory.h:461
friend MyIterator operator-(const MyIterator &rhs, difference_type n)
Definition: memory.h:463
friend bool operator<=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:468
std::forward_iterator_tag iterator_category
Definition: memory.h:441
MyIterator & operator+=(difference_type n)
Definition: memory.h:458
friend bool operator>(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:467
std::ptrdiff_t difference_type
Definition: memory.h:443
MyIterator() noexcept
Definition: memory.h:446
MyIterator(const MyIterator &)=default
MyIterator & operator-=(difference_type n)
Definition: memory.h:459
MyIterator & operator--()
Definition: memory.h:456
T & reference
Definition: memory.h:445
MyIterator operator++(int)
Definition: memory.h:455
MyIterator(pointer ptr)
Definition: memory.h:447
friend bool operator>=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:469
friend bool operator==(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:464
MyIterator operator--(int)
Definition: memory.h:457
friend bool operator!=(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:465
MyIterator(const MyIterator< false > &rhs)
Definition: memory.h:450
T * pointer
Definition: memory.h:444
friend bool operator<(const MyIterator &lhs, const MyIterator &rhs)
Definition: memory.h:466
pointer operator->() const noexcept
Definition: memory.h:453
MyIterator & operator++()
Definition: memory.h:454
reference operator*() const noexcept
Definition: memory.h:452
friend MyIterator operator+(difference_type n, const MyIterator &rhs)
Definition: memory.h:460
friend MyIterator operator-(difference_type n, const MyIterator &rhs)
Definition: memory.h:462
Definition: memory.h:279
T * data() noexcept
Definition: memory.h:417
void resize(size_t n)
Resize the buffer.
Definition: memory.h:543
void push_back(T &&value)
Definition: memory.h:572
iterator end() noexcept
Definition: memory.h:488
ConstIterator const_iterator
Definition: memory.h:482
iterator emplace(const_iterator pos, Args &&... args)
Definition: memory.h:584
std::reverse_iterator< ConstIterator > const_reverse_iterator
Definition: memory.h:493
bool empty() const noexcept
Definition: memory.h:405
reverse_iterator rend() noexcept
Definition: memory.h:497
std::string str(int verbosity=1, unsigned int columns=UINT_MAX) const
Generate a printable representation of the object.
Definition: memory.h:516
Iterator iterator
Definition: memory.h:481
const T & front() const noexcept
Definition: memory.h:413
void assign(InputIterator first, InputIterator last)
Assign new contents to the vector, replacing its current contents.
Definition: memory.h:354
void assign(std::initializer_list< T > il)
Assign new contents to the vector, replacing its current contents.
Definition: memory.h:377
void clear() noexcept
Definition: memory.h:401
iterator erase(const_iterator first, const_iterator last)
Definition: memory.h:505
void shrink_to_fit()
Definition: memory.h:558
std::reverse_iterator< Iterator > reverse_iterator
Definition: memory.h:492
reverse_iterator rbegin() noexcept
Definition: memory.h:494
void emplace_back(Args &&... args)
Definition: memory.h:578
iterator begin() noexcept
Definition: memory.h:484
const T * data() const noexcept
Definition: memory.h:418
T & at(size_t n)
Definition: memory.h:381
const T & operator[](size_t n) const
Definition: memory.h:345
T & back() noexcept
Definition: memory.h:389
const_iterator begin() const noexcept
Definition: memory.h:485
size_t size() const noexcept
Definition: memory.h:424
void reserve(size_t new_cap)
Definition: memory.h:534
const_iterator cbegin() const noexcept
Definition: memory.h:486
const_iterator cend() const noexcept
Definition: memory.h:490
void resize(size_t n, const T &val)
Resize the buffer, and assign a value to any new elements if it grows.
Definition: memory.h:553
const T & back() const noexcept
Definition: memory.h:393
void push_back(const T &value)
Definition: memory.h:567
MyIterator< false > Iterator
Definition: memory.h:478
T & front() noexcept
Definition: memory.h:409
iterator erase(const_iterator pos)
Definition: memory.h:501
size_t capacity() const noexcept
Definition: memory.h:397
const_reverse_iterator rbegin() const noexcept
Definition: memory.h:495
void swap(vector< T, _Alloc > &x)
Exchange the content of the container by the content of x, which is another object of the same type.
Definition: memory.h:432
friend void swap(vector< T, _Alloc > &a, vector< T, _Alloc > &b)
Definition: memory.h:434
size_t max_size() const noexcept
Definition: memory.h:420
const_iterator end() const noexcept
Definition: memory.h:489
void assign(const T &value)
Assign new contents to the vector, replacing its current contents.
Definition: memory.h:362
const T & at(size_t n) const
Definition: memory.h:385
vector< T, _Alloc > & operator=(const vector< T, _Alloc > &copy)
Copy assignment operator.
Definition: memory.h:333
const_reverse_iterator crbegin() const noexcept
Definition: memory.h:496
void pop_back()
Definition: memory.h:563
void assign(size_t n, const T &value)
Assign new contents to the vector, replacing its current contents.
Definition: memory.h:370
virtual ~vector()=default
const_reverse_iterator rend() const noexcept
Definition: memory.h:498
const_reverse_iterator crend() const noexcept
Definition: memory.h:499
T & operator[](size_t n)
Definition: memory.h:342
size_t memory_used(int maximum=0)
memory_used Report used memory
Definition: memory.h:113
size_t memory_initialize(char *buffer, size_t max)
Definition: memory.h:104
std::unordered_map< char *, size_t > _private_memory_lengths
Definition: memoryC.cpp:5
size_t _private_memory_maximum_allocatable
Definition: memoryC.cpp:4
size_t _private_memory_used
Definition: memoryC.cpp:3
void memory_print_status()
memory_print_status Print the state of the memory
Definition: memory.h:122
size_t memory_remaining()
memory_remaining Report used memory
Definition: memory.h:118
void memory_reset_maximum_stack(int64_t level)
memory_reset_maximum_stack Reset the maximum stack used statistic to the currently-used stack
Definition: memory.h:132
Class that manages input options.
Definition: iostream.h:14
vector< T, _Alloc >::Iterator operator+(const typename vector< T, _Alloc >::Iterator &a, int increment)
Definition: memory.h:603
std::ptrdiff_t operator-(const pointer_holder< T > &a, const pointer_holder< T > &b)
Definition: memory.h:596
std::vector< T, A > stdvector
Definition: memory.h:239
std::string args(int argc, char **argv)
Definition: Options.cpp:27
std::ostream & operator<<(std::ostream &os, vector< T, _Alloc > const &obj)
Definition: memory.h:591
Definition: memory.h:158
allocator_< U, typename a_t::template rebind_alloc< U > > other
Definition: memory.h:159