Functions | |
unsigned int | memory_consumption (const bool) |
unsigned int | memory_consumption (const char) |
unsigned int | memory_consumption (const short int) |
unsigned int | memory_consumption (const short unsigned int) |
unsigned int | memory_consumption (const int) |
unsigned int | memory_consumption (const unsigned int) |
unsigned int | memory_consumption (const float) |
unsigned int | memory_consumption (const double) |
unsigned int | memory_consumption (const std::string &s) |
template<typename T > | |
unsigned int | memory_consumption (const std::vector< T > &v) |
template<typename T , int N> | |
unsigned int | memory_consumption (const T(&v)[N]) |
unsigned int | memory_consumption (const std::vector< bool > &v) |
unsigned int | memory_consumption (const std::vector< int > &v) |
unsigned int | memory_consumption (const std::vector< double > &v) |
unsigned int | memory_consumption (const std::vector< float > &v) |
unsigned int | memory_consumption (const std::vector< char > &v) |
unsigned int | memory_consumption (const std::vector< unsigned char > &v) |
template<typename T > | |
unsigned int | memory_consumption (const std::vector< T * > &v) |
unsigned int | memory_consumption (const std::vector< std::string > &v) |
template<typename A , typename B > | |
unsigned int | memory_consumption (const std::pair< A, B > &p) |
template<typename T > | |
unsigned int | memory_consumption (const T *const) |
template<typename T > | |
unsigned int | memory_consumption (T *const) |
unsigned int | memory_consumption (void *const) |
template<typename T > | |
unsigned int | memory_consumption (const std_cxx1x::shared_ptr< T > &) |
template<typename T > | |
unsigned int | memory_consumption (const T &t) |
std::map<>
object?), but rather to aid in the search for memory bottlenecks.
The functions in this namespace work basically by reducing each object to its basics as far as they are known from this place. They do not attempt to know what goes on in each object, if they are not basic types (such as int
or double
) or STL containers (such as vectors
). The method goes as follows: if the object with which a memory_consumption
function from this namespace is an atomic type, the return its size by applying the sizeof
operator to it. If this is not the case, then try to reduce it to more basic types.
For example, if it is a C-style array or a standard C++ std::vector
, then sum up the sizes of the array elements by calling memory_consumption
on each of them. This way, we can also reduce objects of type std::vector<std::vector<double> >
to its atomic types, and can thus determine the memory used even if the sizes of the elements of the outermost vector differ (e.g. the first sub-vector has 3 and the second sub-vector has 10 elements).
There are two exceptions to simply adding up the sizes of the subobjects: for C++ std::vector
objects, we also have to add the size of the vector object, i.e. sizeof(vector<T>)
, to the sizes of the elements. Secondly, for the most common used vectors, such as std::vector<double>
and std::vector<unsigned int>
we determine the size without a loop but rather directly, since we know that the sizes of the elements are constant.
Finally, if we cannot reduce a type T
further, because it is neither atomic nor a known C++ data type, we call a member function T::memory_consumption
on it, which we assume to exist. Almost all classes in the deal.II library have such a function. This way, if we call memory_consumption(v)
on a vector v
of type FullMatrix<double>
, we first reduce this to a loop in which we call memory_consumption(v[i])
, and because there is no such function handling this explicitly, we try to call v[i].memory_consumption()
.
The functions in this namespace and the functionality provided by it live on the assumption that there is either a function memory_consumption(T)
in this namespace determining the amount of memory use by objects of type T
, or that the class T
has a function of that name as member function. While the latter is true for almost all class 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.
Determine the amount of memory in bytes consumed by a bool
variable.
Referenced by FilteredMatrix< VECTOR >::memory_consumption(), hp::QCollection< dim >::memory_consumption(), and memory_consumption().
Determine the amount of memory in bytes consumed by a char
variable.
Determine the amount of memory in bytes consumed by a short int
variable.
Determine the amount of memory in bytes consumed by a short unsigned int
variable.
Determine the amount of memory in bytes consumed by a int
variable.
Determine the amount of memory in bytes consumed by a unsigned int
variable.
Determine the amount of memory in bytes consumed by a float
variable.
Determine the amount of memory in bytes consumed by a double
variable.
Determine an estimate of the amount of memory in bytes consumed by a std::string
variable.
unsigned int MemoryConsumption::memory_consumption | ( | const std::vector< T > & | v | ) | [inline] |
Determine an estimate of the amount of memory in bytes consumed by a std::vector
of certain elements. It does so by looping over all elements of the vector and determining their sizes using the memory_consumption
functions. If the elements 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.
References memory_consumption(), and LAPACKSupport::T.
unsigned int 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 double
s in such arrays (but rather use STL std::vector
s or deal.II Vector
objects), we do not provide specializations like for the std::vector
arrays, but always use the loop over all elements.
References memory_consumption().
Specialization of the determination of the memory consumption of a vector, here for a vector of bool
s.
This is a special case, as the bools are not stored one-by-one, but as a bit field.
Specialization of the determination of the memory consumption of a vector, here for a vector of int
s.
Specialization of the determination of the memory consumption of a vector, here for a vector of double
s.
Specialization of the determination of the memory consumption of a vector, here for a vector of float
s.
Specialization of the determination of the memory consumption of a vector, here for a vector of char
s.
unsigned int 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 char
s.
unsigned int 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.
References LAPACKSupport::T.
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.
unsigned int 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.
References memory_consumption().
unsigned int MemoryConsumption::memory_consumption | ( | const T * const | ) | [inline] |
Return the amount of memory used by a pointer. Make sure that you are really interested in this, and not the amount of memory required by the object pointed to.
References LAPACKSupport::T.
Return the amount of memory used by a pointer. Make sure that you are really interested in this, and not the amount of memory required by the object pointed to.
This function is the same as above, but for non-const pointers
References LAPACKSupport::T.
Return the amount of memory used by a void pointer. Make sure that you are really interested in this, and not the amount of memory required by the object pointed to.
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.
unsigned int MemoryConsumption::memory_consumption | ( | const std_cxx1x::shared_ptr< T > & | ptr | ) | [inline] |
Return the amount of memory used by a shared pointer. Make sure that you are really interested in this, and not the amount of memory required by the object pointed to.
For all other types which are not explicitly listed: try if there is a member function called memory_consumption
. If this is not the case, then the compiler will in any case complain that this last exit does not work.