Reference documentation for deal.II version 8.1.0
memory_consumption.h
1 // ---------------------------------------------------------------------
2 // @f$Id: memory_consumption.h 30517 2013-08-28 14:48:49Z bangerth @f$
3 //
4 // Copyright (C) 2000 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__memory_consumption_h
18 #define __deal2__memory_consumption_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/std_cxx1x/shared_ptr.h>
23 
24 #include <string>
25 #include <complex>
26 #include <vector>
27 #include <cstddef>
28 
30 
31 
89 {
90 
108  template <typename T>
109  inline
110  std::size_t memory_consumption (const T &t);
111 
117  inline
118  std::size_t memory_consumption (const bool);
119 
125  inline
126  std::size_t memory_consumption (const char);
127 
133  inline
134  std::size_t memory_consumption (const short int);
135 
141  inline
142  std::size_t memory_consumption (const short unsigned int);
143 
149  inline
150  std::size_t memory_consumption (const int);
151 
157  inline
158  std::size_t memory_consumption (const unsigned int);
159 
165  inline
166  std::size_t memory_consumption (const unsigned long long int);
167 
173  inline
174  std::size_t memory_consumption (const float);
175 
181  inline
182  std::size_t memory_consumption (const double);
183 
189  inline
190  std::size_t memory_consumption (const long double);
191 
197  template <typename T>
198  inline
199  std::size_t memory_consumption (const std::complex<T> &);
200 
207  inline
208  std::size_t memory_consumption (const std::string &s);
209 
260  template <typename T>
261  inline
262  std::size_t memory_consumption (const std::vector<T> &v);
263 
279  template <typename T, int N>
280  inline
281  std::size_t memory_consumption (const T (&v)[N]);
282 
294  inline
295  std::size_t memory_consumption (const std::vector<bool> &v);
296 
303  inline
304  std::size_t memory_consumption (const std::vector<int> &v);
305 
312  inline
313  std::size_t memory_consumption (const std::vector<double> &v);
314 
321  inline
322  std::size_t memory_consumption (const std::vector<float> &v);
323 
330  inline
331  std::size_t memory_consumption (const std::vector<char> &v);
332 
339  inline
340  std::size_t memory_consumption (const std::vector<unsigned char> &v);
341 
348  template <typename T>
349  inline
350  std::size_t memory_consumption (const std::vector<T *> &v);
351 
365  std::size_t memory_consumption (const std::vector<std::string> &v);
366 
367 
373  template <typename A, typename B>
374  inline
375  std::size_t memory_consumption (const std::pair<A,B> &p);
376 
385  template <typename T>
386  inline
387  std::size_t memory_consumption (const T *const);
388 
397  template <typename T>
398  inline
399  std::size_t memory_consumption (T *const);
400 
416  inline
417  std::size_t memory_consumption (void *const);
418 
427  template <typename T>
428  inline
429  std::size_t memory_consumption (const std_cxx1x::shared_ptr<T> &);
430 }
431 
432 
433 
434 // now comes the implementation of these functions
435 
436 namespace MemoryConsumption
437 {
438  inline
439  std::size_t memory_consumption (const bool)
440  {
441  return sizeof(bool);
442  }
443 
444 
445 
446  inline
447  std::size_t memory_consumption (const char)
448  {
449  return sizeof(char);
450  }
451 
452 
453 
454  inline
455  std::size_t memory_consumption (const short int)
456  {
457  return sizeof(short int);
458  }
459 
460 
461 
462  inline
463  std::size_t memory_consumption (const short unsigned int)
464  {
465  return sizeof(short unsigned int);
466  }
467 
468 
469 
470  inline
471  std::size_t memory_consumption (const int)
472  {
473  return sizeof(int);
474  }
475 
476 
477 
478  inline
479  std::size_t memory_consumption (const unsigned int)
480  {
481  return sizeof(unsigned int);
482  }
483 
484 
485 
486  inline
487  std::size_t memory_consumption (const unsigned long int)
488  {
489  return sizeof(unsigned long int);
490  }
491 
492 
493 
494  inline
495  std::size_t memory_consumption (const unsigned long long int)
496  {
497  return sizeof(unsigned long long int);
498  }
499 
500 
501 
502  inline
503  std::size_t memory_consumption (const float)
504  {
505  return sizeof(float);
506  }
507 
508 
509 
510  inline
511  std::size_t memory_consumption (const double)
512  {
513  return sizeof(double);
514  }
515 
516 
517 
518  inline
519  std::size_t memory_consumption (const long double)
520  {
521  return sizeof(long double);
522  }
523 
524 
525  template <typename T>
526  inline
527  std::size_t memory_consumption (const std::complex<T> &)
528  {
529  return sizeof(std::complex<T>);
530  }
531 
532 
533 
534  inline
535  std::size_t memory_consumption (const std::string &s)
536  {
537  return sizeof(s) + s.length();
538  }
539 
540 
541 
542  template <typename T>
543  std::size_t memory_consumption (const std::vector<T> &v)
544  {
545  std::size_t mem = sizeof(std::vector<T>);
546  const unsigned int n = static_cast<unsigned int>(v.size());
547  for (unsigned int i=0; i<n; ++i)
548  mem += memory_consumption(v[i]);
549  mem += (v.capacity() - n)*sizeof(T);
550  return mem;
551  }
552 
553 
554 
555  template <typename T, int N>
556  std::size_t memory_consumption (const T (&v)[N])
557  {
558  std::size_t mem = 0;
559  for (unsigned int i=0; i<N; ++i)
560  mem += memory_consumption(v[i]);
561  return mem;
562  }
563 
564 
565 
566  inline
567  std::size_t memory_consumption (const std::vector<bool> &v)
568  {
569  return v.capacity() / 8 + sizeof(v);
570  }
571 
572 
573 
574  inline
575  std::size_t memory_consumption (const std::vector<int> &v)
576  {
577  return (v.capacity() * sizeof(int) +
578  sizeof(v));
579  }
580 
581 
582 
583  inline
584  std::size_t memory_consumption (const std::vector<double> &v)
585  {
586  return (v.capacity() * sizeof(double) +
587  sizeof(v));
588  }
589 
590 
591 
592  inline
593  std::size_t memory_consumption (const std::vector<float> &v)
594  {
595  return (v.capacity() * sizeof(float) +
596  sizeof(v));
597  }
598 
599 
600 
601  inline
602  std::size_t memory_consumption (const std::vector<char> &v)
603  {
604  return (v.capacity() * sizeof(char) +
605  sizeof(v));
606  }
607 
608 
609 
610  inline
611  std::size_t memory_consumption (const std::vector<unsigned char> &v)
612  {
613  return (v.capacity() * sizeof(unsigned char) +
614  sizeof(v));
615  }
616 
617 
618 
619  template <typename T>
620  inline
621  std::size_t memory_consumption (const std::vector<T *> &v)
622  {
623  return (v.capacity() * sizeof(T *) +
624  sizeof(v));
625  }
626 
627 
628 
629  template <typename A, typename B>
630  inline
631  std::size_t memory_consumption (const std::pair<A,B> &p)
632  {
633  return (memory_consumption(p.first) +
634  memory_consumption(p.second));
635  }
636 
637 
638 
639  template <typename T>
640  inline
641  std::size_t
642  memory_consumption (const T *const)
643  {
644  return sizeof(T *);
645  }
646 
647 
648 
649  template <typename T>
650  inline
651  std::size_t
653  {
654  return sizeof(T *);
655  }
656 
657 
658 
659  inline
660  std::size_t
661  memory_consumption (void *const)
662  {
663  return sizeof(void *);
664  }
665 
666 
667 
668  template <typename T>
669  inline
670  std::size_t
671  memory_consumption (const std_cxx1x::shared_ptr<T> &)
672  {
673  return sizeof(std_cxx1x::shared_ptr<T>);
674  }
675 
676 
677 
678  template <typename T>
679  inline
680  std::size_t
681  memory_consumption (const T &t)
682  {
683  return t.memory_consumption();
684  }
685 }
686 
687 DEAL_II_NAMESPACE_CLOSE
688 
689 #endif
std::size_t memory_consumption(const T &t)