Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | Static Private Attributes

GrowingVectorMemory< VECTOR > Class Template Reference
[Vector memory management]

Inheritance diagram for GrowingVectorMemory< VECTOR >:
Inheritance graph
[legend]

List of all members.

Classes

struct  Pool

Public Member Functions

 GrowingVectorMemory (const unsigned int initial_size=0, const bool log_statistics=false)
 ~GrowingVectorMemory ()
virtual VECTOR * alloc ()
virtual void free (const VECTOR *const)
virtual std::size_t memory_consumption () const

Static Public Member Functions

static void release_unused_memory ()

Private Types

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

Private Attributes

unsigned int total_alloc
unsigned int current_alloc
bool log_statistics

Static Private Attributes

static Pool pool
static Threads::ThreadMutex mutex

Detailed Description

template<class VECTOR = ::Vector<double>>
class GrowingVectorMemory< VECTOR >

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 preformance penalty. A drawback of this policy might be that vectors once allocated are only released at the end of the program run. Nebertheless, the since they are reused, this should be of no concern. Additionally, the destructor of the Pool warns about memory leaks.

Author:
Guido Kanschat, 1999, 2007

Definition at line 253 of file vector_memory.h.


Member Typedef Documentation

template<class VECTOR = ::Vector<double>>
typedef std::pair<bool, VECTOR*> GrowingVectorMemory< VECTOR >::entry_type [private]

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 326 of file vector_memory.h.


Constructor & Destructor Documentation

template<class VECTOR = ::Vector<double>>
GrowingVectorMemory< VECTOR >::GrowingVectorMemory ( const unsigned int  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<class VECTOR = ::Vector<double>>
GrowingVectorMemory< VECTOR >::~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<class VECTOR = ::Vector<double>>
virtual VECTOR* GrowingVectorMemory< VECTOR >::alloc (  ) [virtual]

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< VECTOR >.

Referenced by FilteredMatrix< VECTOR >::Tvmult(), FilteredMatrix< VECTOR >::Tvmult_add(), FilteredMatrix< VECTOR >::vmult(), and FilteredMatrix< VECTOR >::vmult_add().

template<class VECTOR = ::Vector<double>>
virtual void GrowingVectorMemory< VECTOR >::free ( const VECTOR *  const ) [virtual]

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< VECTOR >.

Referenced by FilteredMatrix< VECTOR >::Tvmult(), FilteredMatrix< VECTOR >::Tvmult_add(), FilteredMatrix< VECTOR >::vmult(), and FilteredMatrix< VECTOR >::vmult_add().

template<class VECTOR = ::Vector<double>>
static void GrowingVectorMemory< VECTOR >::release_unused_memory (  ) [static]

Release all vectors that are not currently in use.

template<class VECTOR = ::Vector<double>>
virtual std::size_t GrowingVectorMemory< VECTOR >::memory_consumption (  ) const [virtual]

Memory consumed by this class and all currently allocated vectors.


Member Data Documentation

template<class VECTOR = ::Vector<double>>
Pool GrowingVectorMemory< VECTOR >::pool [static, private]

Array of allocated vectors.

Definition at line 370 of file vector_memory.h.

template<class VECTOR = ::Vector<double>>
unsigned int GrowingVectorMemory< VECTOR >::total_alloc [private]

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

Definition at line 379 of file vector_memory.h.

template<class VECTOR = ::Vector<double>>
unsigned int GrowingVectorMemory< VECTOR >::current_alloc [private]

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

Definition at line 385 of file vector_memory.h.

template<class VECTOR = ::Vector<double>>
bool GrowingVectorMemory< VECTOR >::log_statistics [private]

A flag controlling the logging of statistics by the destructor.

Definition at line 392 of file vector_memory.h.

template<class VECTOR = ::Vector<double>>
Threads::ThreadMutex GrowingVectorMemory< VECTOR >::mutex [static, private]

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

Definition at line 399 of file vector_memory.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Fri Feb 3 2012 06:04:09 by doxygen 1.7.2