<commit_before>//----------------------------  vector_memory.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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.
//
//----------------------------  vector_memory.h  ---------------------------
#ifndef __deal2__vector_memory_h
#define __deal2__vector_memory_h


#include <base/config.h>
#include <base/subscriptor.h>
#include <base/logstream.h>
#include <base/thread_management.h>
#include <lac/vector.h>

#include <vector>


/*! @addtogroup LAC
 *@{
 */

/**
 * Memory management for vectors. This class is used by all
 * iterative methods to allocate space for auxilliary
 * vectors. This class is used to avoid interaction with the
 * operating system whenever a vector is needed. Especially, when
 * an iterative method is invoked as part of an outer iteration,
 * this would lead to runtime overhead and memory fragmentation.
 *
 * Classes derived from this class implement a more or less
 * sophisticated management of vectors. One of these has to be
 * applied by the user according to his needs.
 */
template<class Vector = ::Vector<double> >
class VectorMemory : public Subscriptor
{
  public:

				     /**
				      * Virtual destructor is needed
				      * as there are virtual functions
				      * in this class.
				      */
    virtual ~VectorMemory() {};

				     /**
				      * Return new vector from the pool.
				      */
    virtual Vector* alloc() = 0;
    
				     /**
				      * Return a vector into the pool
				      * for later use.
				      */
    virtual void free (const Vector * const) = 0;
				     /**
				      * No more available vectors.
				      */
    DeclException0(ExcNoMoreVectors);
				     /**
				      * Vector was not allocated from
				      * this memory pool.
				      */
    DeclException0(ExcNotAllocatedHere);
};


/**
 * Simple memory management.  This memory class is just made for
 * tests. It just allocates and deletes
 * vectors as needed from the global heap, i.e. performs no
 * specially adapted actions to the purpose of this class.
 */
template<class Vector = ::Vector<double> >
class PrimitiveVectorMemory : public VectorMemory<Vector>
{
  public:
				     /**
				      * Constructor.
				      */
    PrimitiveVectorMemory () {}

				     /**
				      * Allocate a vector
				      * from the global heap.
				      */
    virtual Vector* alloc()
      {
	return new Vector();
      }
    
				     /**
				      * Return a vector to the global heap.
				      */
    virtual void free (const Vector * const v)
      {
	delete v;
      }
};


/**
 * Memory keeping allocated vectors.  This @p{VectorMemory} is able to
 * grow infinitely (according to computer memory).  A vector once
 * allocated will stay in the memory pool, though, and it will be
 * reused in later allocation.
 * 
 * @author <NAME>, 1999
 */
template<class Vector = ::Vector<double> >
class GrowingVectorMemory : public VectorMemory<Vector>
{
  public:
				     /**
				      * Constructor.
				      * The argument allows to
				      * preallocate a certain number
				      * of vectors.
				      */
    GrowingVectorMemory (const unsigned int initial_size = 0);

				     /**
				      * 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.
				      */
    ~GrowingVectorMemory();
    
				     /**
				      * Return new vector from the pool.
				      */
    virtual Vector* alloc();
    
				     /**
				      * Return a vector into the pool
				      * for later use.
				      */
    virtual void free (const Vector * const);

  private:
				     /**
				      * Type to enter into the
				      * array. First component will be
				      * a flag telling whether the
				      * vector is used, second the
				      * vector itself.
				      */
    typedef std::pair<bool, Vector*> entry_type;

				     /**
				      * Array of allocated vectors.
				      */
    std::vector<entry_type> pool;
    
				     /**
				      * Overall number of allocations.
				      */
    unsigned int n_alloc;

				     /**
				      * Mutex to synchronise access to
				      * internal data of this object
				      * from multiple threads.
				      */
    Threads::ThreadMutex mutex;
};


/*@}*/<commit_msg>doc changed<commit_after>//----------------------------  vector_memory.h  ---------------------------
//    $Id$
//    Version: $Name$
//
//    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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.
//
//----------------------------  vector_memory.h  ---------------------------
#ifndef __deal2__vector_memory_h
#define __deal2__vector_memory_h


#include <base/config.h>
#include <base/subscriptor.h>
#include <base/logstream.h>
#include <base/thread_management.h>
#include <lac/vector.h>

#include <vector>


/**
 * Memory management base class for vectors. This is an abstract base
 * class used by all iterative methods to allocate space for
 * auxilliary vectors. An object of a derived class with an actual
 * implementation of the memory management must be created by the
 * application program to be used in iterative methods.
 *
 * The purpose of this class is avoiding interaction with the
 * operating system whenever a vector is needed. Especially, when an
 * iterative method is invoked as part of an outer iteration, this
 * would lead to runtime overhead and memory fragmentation.
 *
 * @author <NAME>, 1998-2003
*/
template<class Vector = ::Vector<double> >
class VectorMemory : public Subscriptor
{
  public:

				     /**
				      * Virtual destructor is needed
				      * as there are virtual functions
				      * in this class.
				      */
    virtual ~VectorMemory() {};

				     /**
				      * Return new vector from the pool.
				      */
    virtual Vector* alloc() = 0;
    
				     /**
				      * Return a vector into the pool
				      * for later use.
				      */
    virtual void free (const Vector * const) = 0;
				     /**
				      * No more available vectors.
				      */
    DeclException0(ExcNoMoreVectors);
				     /**
				      * Vector was not allocated from
				      * this memory pool.
				      */
    DeclException0(ExcNotAllocatedHere);
};


/**
 * Simple memory management.  This memory class is just made for
 * tests. It just allocates and deletes
 * vectors as needed from the global heap, i.e. performs no
 * specially adapted actions to the purpose of this class.
 */
template<class Vector = ::Vector<double> >
class PrimitiveVectorMemory : public VectorMemory<Vector>
{
  public:
				     /**
				      * Constructor.
				      */
    PrimitiveVectorMemory () {}

				     /**
				      * Allocate a vector
				      * from the global heap.
				      */
    virtual Vector* alloc()
      {
	return new Vector();
      }
    
				     /**
				      * Return a vector to the global heap.
				      */
    virtual void free (const Vector * const v)
      {
	delete v;
      }
};


/**
 * Memory keeping allocated vectors.  This @p{VectorMemory} is able to
 * grow infinitely (according to computer memory).  A vector once
 * allocated will stay in the memory pool, though, and it will be
 * reused in later allocation.
 * 
 * @author <NAME>, 1999
 */
template<class Vector = ::Vector<double> >
class GrowingVectorMemory : public VectorMemory<Vector>
{
  public:
				     /**
				      * Constructor.
				      * The argument allows to
				      * preallocate a certain number
				      * of vectors.
				      */
    GrowingVectorMemory (const unsigned int initial_size = 0);

				     /**
				      * 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.
				      */
    ~GrowingVectorMemory();
    
				     /**
				      * Return new vector from the pool.
				      */
    virtual Vector* alloc();
    
				     /**
				      * Return a vector into the pool
				      * for later use.
				      */
    virtual void free (const Vector * const);

  private:
				     /**
				      * Type to enter into the
				      * array. First component will be
				      * a flag telling whether the
				      * vector is used, second the
				      * vector itself.
				      */
    typedef std::pair<bool, Vector*> entry_type;

				     /**
				      * Array of allocated vectors.
				      */
    std::vector<entry_type> pool;
    
				     /**
				      * Overall number of allocations.
				      */
    unsigned int n_alloc;

				     /**
				      * Mutex to synchronise access to
				      * internal data of this object
				      * from multiple threads.
				      */
    Threads::ThreadMutex mutex;
};

{'fraction_non_alphanumeric': 0.10905827702702703, 'fraction_numerical': 0.008234797297297296, 'mean_word_length': 1.7481868291267768, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6256901', 'n_tokens_mistral': 3072, 'n_tokens_neox': 2383, 'n_words': 927}