ASPECT
Classes | Public Member Functions | Private Attributes | List of all members
aspect::Utilities::ScratchSpace< T > Class Template Reference

Classes

class  ScopedScratchObject
 

Public Member Functions

T & get_object_from_pool ()
 
 ~ScratchSpace ()
 
void return_object_to_pool (T &t)
 

Private Attributes

::Threads::ThreadLocalStorage< std::list< std::pair< T, bool > > > object_list
 

Detailed Description

template<typename T>
class aspect::Utilities::ScratchSpace< T >

A class that allows for creating reusable chunks of memory. When this class's get_object_from_pool() function is called, it returns a reference to a currently unused object, or creates a new one if non are available. When done with an object it can be returned to the pool for later use. This is particularly useful when needing the same size memory in a function which is called in a loop. Since the objects are not reset, using this scratch space can prevent reallocating memory over and over. This class works in recursive functions. The class is recommended to be used with the ScopedScratchObject, which will automatically return the object to the pool when the ScopedScratchObject goes out of scope.

Definition at line 89 of file utilities.h.

Constructor & Destructor Documentation

§ ~ScratchSpace()

template<typename T>
aspect::Utilities::ScratchSpace< T >::~ScratchSpace ( )

Destructor

Member Function Documentation

§ get_object_from_pool()

template<typename T>
T& aspect::Utilities::ScratchSpace< T >::get_object_from_pool ( )

returns an object from the pool. If there are no unused objects, it creates a new object and returns it.

§ return_object_to_pool()

template<typename T>
void aspect::Utilities::ScratchSpace< T >::return_object_to_pool ( T &  t)

returns an object to the pool to be reused later.

Member Data Documentation

§ object_list

template<typename T>
::Threads::ThreadLocalStorage<std::list<std::pair<T,bool> > > aspect::Utilities::ScratchSpace< T >::object_list
private

Definition at line 135 of file utilities.h.


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