]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Remove memory_consumption(std::vector<int>) et al.
authorDavid Wells <wellsd2@rpi.edu>
Fri, 2 Oct 2015 18:34:03 +0000 (14:34 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Fri, 2 Oct 2015 20:27:28 +0000 (16:27 -0400)
This may be implemented generically now that an implementation of
memory_consumption for all fundamental types is available.

include/deal.II/base/memory_consumption.h

index d9bf795b7ae43af57ec84c1bf057dbebb5a1dbf7..2e93c0e50a82c4cd601efdd21ccc7569c5b08d7c 100644 (file)
@@ -199,50 +199,6 @@ namespace MemoryConsumption
   inline
   std::size_t memory_consumption (const std::vector<bool> &v);
 
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of <tt>int</tt>s.
-   */
-  inline
-  std::size_t memory_consumption (const std::vector<int> &v);
-
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of <tt>double</tt>s.
-   */
-  inline
-  std::size_t memory_consumption (const std::vector<double> &v);
-
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of <tt>float</tt>s.
-   */
-  inline
-  std::size_t memory_consumption (const std::vector<float> &v);
-
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of <tt>char</tt>s.
-   */
-  inline
-  std::size_t memory_consumption (const std::vector<char> &v);
-
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of <tt>unsigned char</tt>s.
-   */
-  inline
-  std::size_t memory_consumption (const std::vector<unsigned char> &v);
-
-  /**
-   * Specialization of the determination of the memory consumption of a
-   * vector, here for a vector of pointers.
-   */
-  template <typename T>
-  inline
-  std::size_t memory_consumption (const std::vector<T *> &v);
-
-
   /**
    * Determine an estimate of the amount of memory in bytes consumed by a pair
    * of values.
@@ -360,12 +316,21 @@ namespace MemoryConsumption
   template <typename T>
   std::size_t memory_consumption (const std::vector<T> &v)
   {
-    std::size_t mem = sizeof(std::vector<T>);
-    const unsigned int n = static_cast<unsigned int>(v.size());
-    for (unsigned int i=0; i<n; ++i)
-      mem += memory_consumption(v[i]);
-    mem += (v.capacity() - n)*sizeof(T);
-    return mem;
+    // shortcut for types that do not allocate memory themselves
+    if (std_cxx11::is_fundamental<T>::value || std_cxx11::is_pointer<T>::value)
+      {
+        return v.capacity()*sizeof(T) + sizeof(v);
+      }
+    else
+      {
+        std::size_t mem = sizeof(std::vector<T>);
+        for (unsigned int i=0; i<v.size(); ++i)
+          {
+            mem += memory_consumption(v[i]);
+          }
+        mem += (v.capacity() - v.size())*sizeof(T);
+        return mem;
+      }
   }
 
 
@@ -389,61 +354,6 @@ namespace MemoryConsumption
 
 
 
-  inline
-  std::size_t memory_consumption (const std::vector<int> &v)
-  {
-    return (v.capacity() * sizeof(int) +
-            sizeof(v));
-  }
-
-
-
-  inline
-  std::size_t memory_consumption (const std::vector<double> &v)
-  {
-    return (v.capacity() * sizeof(double) +
-            sizeof(v));
-  }
-
-
-
-  inline
-  std::size_t memory_consumption (const std::vector<float> &v)
-  {
-    return (v.capacity() * sizeof(float) +
-            sizeof(v));
-  }
-
-
-
-  inline
-  std::size_t memory_consumption (const std::vector<char> &v)
-  {
-    return (v.capacity() * sizeof(char) +
-            sizeof(v));
-  }
-
-
-
-  inline
-  std::size_t memory_consumption (const std::vector<unsigned char> &v)
-  {
-    return (v.capacity() * sizeof(unsigned char) +
-            sizeof(v));
-  }
-
-
-
-  template <typename T>
-  inline
-  std::size_t memory_consumption (const std::vector<T *> &v)
-  {
-    return (v.capacity() * sizeof(T *) +
-            sizeof(v));
-  }
-
-
-
   template <typename A, typename B>
   inline
   std::size_t memory_consumption (const std::pair<A,B> &p)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.