Reference documentation for deal.II version Git 0183d66 2014-10-17 10:54:07 +0200
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Functions
MemoryConsumption Namespace Reference

Functions

template<typename T >
std::size_t memory_consumption (const T &t)
 
std::size_t memory_consumption (const bool)
 
std::size_t memory_consumption (const char)
 
std::size_t memory_consumption (const short int)
 
std::size_t memory_consumption (const short unsigned int)
 
std::size_t memory_consumption (const int)
 
std::size_t memory_consumption (const unsigned int)
 
std::size_t memory_consumption (const unsigned long long int)
 
std::size_t memory_consumption (const float)
 
std::size_t memory_consumption (const double)
 
std::size_t memory_consumption (const long double)
 
template<typename T >
std::size_t memory_consumption (const std::complex< T > &)
 
template<typename T >
std::size_t memory_consumption (const VectorizedArray< T > &)
 
std::size_t memory_consumption (const std::string &s)
 
template<typename T >
std::size_t memory_consumption (const std::vector< T > &v)
 
template<typename T , int N>
std::size_t memory_consumption (const T(&v)[N])
 
std::size_t memory_consumption (const std::vector< bool > &v)
 
std::size_t memory_consumption (const std::vector< int > &v)
 
std::size_t memory_consumption (const std::vector< double > &v)
 
std::size_t memory_consumption (const std::vector< float > &v)
 
std::size_t memory_consumption (const std::vector< char > &v)
 
std::size_t memory_consumption (const std::vector< unsigned char > &v)
 
template<typename T >
std::size_t memory_consumption (const std::vector< T * > &v)
 
std::size_t memory_consumption (const std::vector< std::string > &v)
 
template<typename A , typename B >
std::size_t memory_consumption (const std::pair< A, B > &p)
 
template<typename T >
std::size_t memory_consumption (const T *const)
 
template<typename T >
std::size_t memory_consumption (T *const)
 
std::size_t memory_consumption (void *const)
 
template<typename T >
std::size_t memory_consumption (const std_cxx11::shared_ptr< T > &)
 
std::size_t memory_consumption (const unsigned long int)
 

Detailed Description

This namespace provides functions helping to determine the amount of memory used by objects. The goal is not necessarily to give the amount of memory used up to the last bit (what is the memory used by an STL std::map<> object?), but rather to aid in the search for memory bottlenecks.

This namespace has a single member function memory_consumption() and a lot of specializations. Depending on the argument type of the function, there are several modes of operation:

  1. The argument is a standard C++ data type, namely, bool, float, double or any of the integer types. In that case, memory_consumption() simple returns sizeof of its argument. The library also provides an estimate for the amount of memory occupied by a std::string this way.

  2. For objects, which are neither standard types, nor vectors, memory_consumption() will simply call the member function of same name. It is up to the implementation of the data type to provide a good estimate of the amount of memory used. Inside this function, the use of MemoryConsumpton::memory_consumption() for compounds of the class helps to obtain this estimate. Most classes in the deal.II library have such a member function.

  3. For vectors and C++ arrays of objects, memory_consumption() recursively calls itself for all entries and adds the results to the size of the object itself. Some optimized specializations for standard data types exist.

  4. For vectors of regular pointers, memory_consumption(T*) returns the size of the vector of pointers, ignoring the size of the objects.

Extending this namespace

The function in this namespace and the functionality provided by it relies on the assumption that there is either a specialized function memory_consumption(T) in this namespace determining the amount of memory used by objects of type T, or that the class T has a member function of that name. While the latter is true for almost all classes in deal.II, we have only implemented the first kind of functions for the most common data types, such as atomic types, strings, C++ vectors, C-style arrays, and C++ pairs. These functions therefore do not cover, for example, C++ maps, lists, etc. If you need such functions feel free to implement them and send them to us for inclusion.

Author
Wolfgang Bangerth, documentation updated by Guido Kanschat
Date
2000

Function Documentation

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const T &  t)
inline

This function is the generic interface for determining the memory used by an object. If no specialization for the type T is specified, it will call the member function t.memory_consumption().

The library provides specializations for all basic C++ data types. Every additional type needs to have a member function memory_consumption() callable for constant objects to be used in this framework.

Definition at line 702 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const bool  )
inline

Determine the amount of memory in bytes consumed by a bool variable.

Definition at line 450 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const char  )
inline

Determine the amount of memory in bytes consumed by a char variable.

Definition at line 458 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const short  int)
inline

Determine the amount of memory in bytes consumed by a short int variable.

Definition at line 466 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const short unsigned  int)
inline

Determine the amount of memory in bytes consumed by a short unsigned int variable.

Definition at line 474 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const int  )
inline

Determine the amount of memory in bytes consumed by a int variable.

Definition at line 482 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const unsigned  int)
inline

Determine the amount of memory in bytes consumed by a unsigned int variable.

Definition at line 490 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const unsigned long long  int)
inline

Determine the amount of memory in bytes consumed by a unsigned long long int variable.

Definition at line 506 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const float  )
inline

Determine the amount of memory in bytes consumed by a float variable.

Definition at line 514 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const double  )
inline

Determine the amount of memory in bytes consumed by a double variable.

Definition at line 522 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const long  double)
inline

Determine the amount of memory in bytes consumed by a long double variable.

Definition at line 530 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const std::complex< T > &  )
inline

Determine the amount of memory in bytes consumed by a std::complex variable.

Definition at line 539 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const VectorizedArray< T > &  )
inline

Determine the amount of memory in bytes consumed by a VectorizedArray variable.

Definition at line 548 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::string &  s)
inline

Determine an estimate of the amount of memory in bytes consumed by a std::string variable.

Definition at line 556 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const std::vector< T > &  v)
inline

Determine the amount of memory in bytes consumed by a std::vector of elements of type T by recursively calling memory_consumption() for each entry.

This function loops over all entries of the vector and determines their sizes using memory_consumption() for each v[i]. If the entries are of constant size, there might be another global function memory_consumption() for this data type or if there is a member function of that class of that names that returns a constant value and the compiler will unroll this loop so that the operation is fast. If the size of the data elements is variable, for example if they do memory allocation themselves, then the operation will necessarily be more expensive.

Using the algorithm, in particular the loop over all elements, it is possible to also compute the memory consumption of vectors of vectors, vectors of strings, etc, where the individual elements may have vastly different sizes.

Note that this algorithm also takes into account the size of elements that are allocated by this vector but not currently used.

For the most commonly used vectors, there are special functions that compute the size without a loop. This also applies for the special case of vectors of bools.

Definition at line 564 of file memory_consumption.h.

template<typename T , int N>
std::size_t MemoryConsumption::memory_consumption ( const T(&)  v[N])
inline

Estimate the amount of memory (in bytes) occupied by a C-style array. Since in this library we do not usually store simple data elements like doubles in such arrays (but rather use STL std::vectors or deal.II Vector objects), we do not provide specializations like for the std::vector arrays, but always use the loop over all elements.

Definition at line 577 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< bool > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of bools.

This is a special case, as the bools are not stored one-by-one, but as a bit field.

Definition at line 588 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< int > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of ints.

Definition at line 596 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< double > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of doubles.

Definition at line 605 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< float > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of floats.

Definition at line 614 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< char > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of chars.

Definition at line 623 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< unsigned char > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of unsigned chars.

Definition at line 632 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const std::vector< T * > &  v)
inline

Specialization of the determination of the memory consumption of a vector, here for a vector of pointers.

Definition at line 642 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( const std::vector< std::string > &  v)

Specialization of the determination of the memory consumption of a vector, here for a vector of strings. This function is not necessary from a strict C++ viewpoint, since it could be generated, but is necessary for compatibility with IBM's xlC 5.0 compiler, and doesn't harm for other compilers as well.

template<typename A , typename B >
std::size_t MemoryConsumption::memory_consumption ( const std::pair< A, B > &  p)
inline

Determine an estimate of the amount of memory in bytes consumed by a pair of values.

Definition at line 652 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const T * const  )
inline

Return the amount of memory used by a pointer.

Note
This returns the size of the pointer, not of the object pointed to.

Definition at line 663 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( T * const  )
inline

Return the amount of memory used by a pointer.

Note
This returns the size of the pointer, not of the object pointed to.

Definition at line 673 of file memory_consumption.h.

std::size_t MemoryConsumption::memory_consumption ( void * const  )
inline

Return the amount of memory used by a void pointer.

Note that we needed this function since void is no type and a void* is thus not caught by the general T* template function above.

Note
This returns the size of the pointer, not of the object pointed to.

Definition at line 682 of file memory_consumption.h.

template<typename T >
std::size_t MemoryConsumption::memory_consumption ( const std_cxx11::shared_ptr< T > &  )
inline

Return the amount of memory used by a shared pointer.

Note
This returns the size of the pointer, not of the object pointed to.

Definition at line 692 of file memory_consumption.h.