Reference documentation for deal.II version 8.4.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes | List of all members
GrowingVectorMemory< VectorType > Class Template Reference

#include <deal.II/lac/vector_memory.h>

Inheritance diagram for GrowingVectorMemory< VectorType >:


struct  Pool

Public Types

typedef types::global_dof_index size_type

Public Member Functions

 GrowingVectorMemory (const size_type initial_size=0, const bool log_statistics=false)
virtual ~GrowingVectorMemory ()
virtual VectorType * alloc ()
virtual void free (const VectorType *const)
virtual std::size_t memory_consumption () const
- Public Member Functions inherited from VectorMemory< VectorType >
virtual ~VectorMemory ()
 DeclException0 (ExcNoMoreVectors)
 DeclException0 (ExcNotAllocatedHere)
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 Subscriptor (const Subscriptor &)
virtual ~Subscriptor ()
Subscriptoroperator= (const Subscriptor &)
void subscribe (const char *identifier=0) const
void unsubscribe (const char *identifier=0) const
unsigned int n_subscriptions () const
void list_subscribers () const
 DeclException3 (ExcInUse, int, char *, std::string &,<< "Object of class "<< arg2<< " is still used by "<< arg1<< " other objects."<< "\n\n"<< "(Additional information: "<< arg3<< ")\n\n"<< "See the entry in the Frequently Asked Questions of "<< "deal.II (linked to from for "<< "a lot more information on what this error means and "<< "how to fix programs in which it happens.")
 DeclException2 (ExcNoSubscriber, char *, char *,<< "No subscriber with identifier <"<< arg2<< "> subscribes to this object of class "<< arg1<< ". Consequently, it cannot be unsubscribed.")
template<class Archive >
void serialize (Archive &ar, const unsigned int version)

Static Public Member Functions

static void release_unused_memory ()

Private Types

typedef std::pair< bool, VectorType * > entry_type

Private Attributes

size_type total_alloc
size_type current_alloc
bool log_statistics

Static Private Attributes

static Pool pool
static Threads::Mutex mutex

Detailed Description

template<typename VectorType = ::Vector<double>>
class GrowingVectorMemory< VectorType >

A pool based memory management class. See the documentation of the base class for a description of its purpose.

Each time a vector is requested from this class, it checks if it has one available and returns its address, or allocates a new one on the heap. If a vector is returned, through the free() member function, it doesn't return it to the operating system memory subsystem, but keeps it around unused for later use if alloc() is called again, or until the object is destroyed. The class therefore avoid the overhead of repeatedly allocating memory on the heap if temporary vectors are required and released frequently; on the other hand, it doesn't release once-allocated memory at the earliest possible time and may therefore lead to an increased overall memory consumption.

All GrowingVectorMemory objects of the same vector type use the same memory Pool. Therefore, functions can create such a VectorMemory object whenever needed without performance penalty. A drawback of this policy might be that vectors once allocated are only released at the end of the program run. Nevertheless, the since they are reused, this should be of no concern. Additionally, the destructor of the Pool warns about memory leaks.

Guido Kanschat, 1999, 2007

Definition at line 229 of file vector_memory.h.

Member Typedef Documentation

template<typename VectorType = ::Vector<double>>
typedef types::global_dof_index GrowingVectorMemory< VectorType >::size_type

Declare type for container size.

Definition at line 235 of file vector_memory.h.

template<typename VectorType = ::Vector<double>>
typedef std::pair<bool, VectorType *> GrowingVectorMemory< VectorType >::entry_type

Type to enter into the array. First component will be a flag telling whether the vector is used, second the vector itself.

Definition at line 285 of file vector_memory.h.

Constructor & Destructor Documentation

template<typename VectorType = ::Vector<double>>
GrowingVectorMemory< VectorType >::GrowingVectorMemory ( const size_type  initial_size = 0,
const bool  log_statistics = false 

Constructor. The argument allows to preallocate a certain number of vectors. The default is not to do this.

template<typename VectorType = ::Vector<double>>
virtual GrowingVectorMemory< VectorType >::~GrowingVectorMemory ( )

Destructor. Release all vectors. This destructor also offers some statistic on the number of allocated vectors.

The log file will also contain a warning message, if there are allocated vectors left.

Member Function Documentation

template<typename VectorType = ::Vector<double>>
virtual VectorType* GrowingVectorMemory< VectorType >::alloc ( )

Return a pointer to a new vector. The number of elements or their subdivision into blocks (if applicable) is unspecified and users of this function should reset vectors to their proper size. The same holds for the contents of vectors: they are unspecified.

Implements VectorMemory< VectorType >.

template<typename VectorType = ::Vector<double>>
virtual void GrowingVectorMemory< VectorType >::free ( const VectorType *  const)

Return a vector and indicate that it is not going to be used any further by the instance that called alloc() to get a pointer to it.

For the present class, this means retaining the vector for later reuse by the alloc() method.

Implements VectorMemory< VectorType >.

template<typename VectorType = ::Vector<double>>
static void GrowingVectorMemory< VectorType >::release_unused_memory ( )

Release all vectors that are not currently in use.

template<typename VectorType = ::Vector<double>>
virtual std::size_t GrowingVectorMemory< VectorType >::memory_consumption ( ) const

Memory consumed by this class and all currently allocated vectors.

Member Data Documentation

template<typename VectorType = ::Vector<double>>
Pool GrowingVectorMemory< VectorType >::pool

Array of allocated vectors.

Definition at line 319 of file vector_memory.h.

template<typename VectorType = ::Vector<double>>
size_type GrowingVectorMemory< VectorType >::total_alloc

Overall number of allocations. Only used for bookkeeping and to generate output at the end of an object's lifetime.

Definition at line 325 of file vector_memory.h.

template<typename VectorType = ::Vector<double>>
size_type GrowingVectorMemory< VectorType >::current_alloc

Number of vectors currently allocated in this object; used for detecting memory leaks.

Definition at line 330 of file vector_memory.h.

template<typename VectorType = ::Vector<double>>
bool GrowingVectorMemory< VectorType >::log_statistics

A flag controlling the logging of statistics by the destructor.

Definition at line 335 of file vector_memory.h.

template<typename VectorType = ::Vector<double>>
Threads::Mutex GrowingVectorMemory< VectorType >::mutex

Mutex to synchronise access to internal data of this object from multiple threads.

Definition at line 341 of file vector_memory.h.

The documentation for this class was generated from the following file: