*/
virtual void free (const VECTOR * const) = 0;
+ /**
+ * Access the default memory
+ * space deal.II is offering for
+ * vectors of this kind.
+ *
+ * This function accesses static
+ * VectorMemory objects used by
+ * deal.II classes to allocate
+ * vectors. It is good practice
+ * to use these in your program
+ * as well, in order to optimize
+ * memory usage.
+ */
+ static VectorMemory<VECTOR>& default_pool();
+
/** @addtogroup Exceptions
* @{ */
* this memory pool.
*/
DeclException0(ExcNotAllocatedHere);
+
+ /**
+ * You tried to access the
+ * deal.II
+ * VectorMemory::default_pool(),
+ * but the vector class you are
+ * using is not a standard
+ * deal.II vector class.
+ */
+ DeclException0(ExcNoDefaultMemoryForThisVectorClass);
//@}
};
*/
unsigned int memory_consumption() const;
+ /**
+ * A flag controlling the logging
+ * of statistics at the end.
+ */
+ bool log_statistics;
+
private:
/**
* Type to enter into the
template <typename VECTOR>
GrowingVectorMemory<VECTOR>::GrowingVectorMemory (const unsigned int initial_size)
:
+ log_statistics(false),
pool(initial_size)
{
Threads::ThreadMutex::ScopedLock lock(mutex);
++n;
delete i->second;
}
- deallog << "GrowingVectorMemory:Overall allocated vectors: "
- << n_alloc << std::endl;
- deallog << "GrowingVectorMemory:Maximum allocated vectors: "
- << pool.size() << std::endl;
+ if (log_statistics)
+ {
+ deallog << "GrowingVectorMemory:Overall allocated vectors: "
+ << n_alloc << std::endl;
+ deallog << "GrowingVectorMemory:Maximum allocated vectors: "
+ << pool.size() << std::endl;
+ }
pool.clear ();
// write out warning if memory leak
--- /dev/null
+//---------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2007 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+#include <lac/vector_memory.h>
+#include <lac/vector.h>
+#include <lac/block_vector.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+
+namespace
+{
+ GrowingVectorMemory<Vector<double> > default_pool_Vector_double;
+ GrowingVectorMemory<Vector<float> > default_pool_Vector_float;
+ GrowingVectorMemory<BlockVector<double> > default_pool_BlockVector_double;
+ GrowingVectorMemory<BlockVector<float> > default_pool_BlockVector_float;
+
+ template<class VECTOR>
+ inline
+ VectorMemory<VECTOR>*
+ default_pool_select()
+ {
+ Assert(false, typename VectorMemory<VECTOR>::ExcNoDefaultMemoryForThisVectorClass());
+ return 0;
+ }
+
+
+ template <>
+ inline
+ VectorMemory<Vector<double> >*
+ default_pool_select<Vector<double> >()
+ {
+ return &default_pool_Vector_double;
+ }
+
+
+ template <>
+ inline
+ VectorMemory<Vector<float> >*
+ default_pool_select<Vector<float> >()
+ {
+ return &default_pool_Vector_float;
+ }
+
+
+
+ template <>
+ inline
+ VectorMemory<BlockVector<double> >*
+ default_pool_select<BlockVector<double> >()
+ {
+ return &default_pool_BlockVector_double;
+ }
+
+
+ template <>
+ inline
+ VectorMemory<BlockVector<float> >*
+ default_pool_select<BlockVector<float> >()
+ {
+ return &default_pool_BlockVector_float;
+ }
+
+}
+
+
+template <class VECTOR>
+VectorMemory<VECTOR>&
+VectorMemory<VECTOR>::default_pool()
+{
+ return *default_pool_select<VECTOR>();
+}
+
+
+template class VectorMemory<Vector<double> >;
+template class VectorMemory<Vector<float> >;
+template class VectorMemory<BlockVector<double> >;
+template class VectorMemory<BlockVector<float> >;
+
+
+DEAL_II_NAMESPACE_CLOSE